Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
118 lines (87 loc) · 3.03 KB

File metadata and controls

118 lines (87 loc) · 3.03 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

Goog Practice

Goood practice allow keep your code in harmony. Writing code do not tell youtself that he is only for you. Will come once a time that you will need help somone. So if your code will be unreadable it will take more time to analyze what's the problem is.

Good tips

Controller

  • Before loading View load first Model.
  • Name of the variable create from name model and word Model ($NameModel)
  • Variable view we use usually once so create just $view
public function myMethod(){
    $firstModel = $this->loadModel('First');
    $secondModel = $this->loadModel('Second');
    $view = $this->loadView('Index');
}

If you have some validation access code try to do like this

public function myProcetedMethod(){
    if($this->baseClass->session->authLogin() != true){
        return $this->router->reditect('page/index');
    }

    $firstModel = $this->loadModel('First');
    $secondModel = $this->loadModel('Second');
    $view = $this->loadView('Index');
}

If you have some validation $_POST, $_GET with msg code try to do like this

public function myProcetedAndPostMethod(){
    if ($this->baseClass->session->authLogin() != true) {
        return $this->router->reditect('page/index');
    }

    if (isset($_POST['someValue'])) {
        return $this->baseClass->msg->add('s', 'Yes Post!.', 'page/index');
    }

    $firstModel = $this->loadModel('First');
    $secondModel = $this->loadModel('Second');
    $view = $this->loadView('Index');

}

But if you use json try to use like this

public function myProcetedAndPostMethod(){
    if ($this->baseClass->session->authLogin() != true) {
        return $this->router->reditect('page/index');
    }

    if (!isset($_POST['someValue']) AND !empty($_POST['someValue'])) {
        return Dframe\Router\Response::renderJSON(['code' => '400', 'response' => 'empty someVlue Post'])->status(400);
    }

    $firstModel = $this->loadModel('First');
    $secondModel = $this->loadModel('Second');
    //...
}

Custom Response ?

    public function customHeader() 
    {
        $view = $this->loadView('Index');
        $view->assign('contents', 'Example assign');
        return Dframe\Router\Response::create($view->fetch('index'))
            ->status(200)
            ->headers([
                'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', 
                'Cache-Control' => 'no-cache',
                'Pragma', 'no-cache'
             ]);
    }

View

In view not a lot is happend. In standard View/index.php should be assign should for front-developer.

<?php
namespace View;

use Dframe\Config;
use Dframe\View\View;

class IndexView extends View
{

    public function init(){
        if(isset($this->router)){
            $this->assign('router', $this->router);
        }
    

If you use Dframe\Session add

    $this->assign('authLogin', $this->baseClass->session->authLogin());

Yes you can assign to View Model class for example generate url links or to set isset for permission user etc.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.