Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is this a good practice

Hi guys,

I just want to ask you guys if what im doing is a good practice in coding, I'm referencing the $this->request as self::$hit on my basecontroller and using parent::$hit on my homecontroller so that i dont have to use $this->request everytime i get the value of fields in a form.

BaseController.php

class BaseController extends Controller
{
    public static $hit;

    public function initialize()
    {

        /* reference the request */
        self::$hit = $this->request;
    }
}

HomeController.php

class HomeController extends BaseController
{

    private static $username, $fname, $lname, $email, $password;

    public function initialize()
    {
        parent::initialize();
    }


    public function RFvalidationAction($form)
    {
        switch($form)
        {
            case ($form->isValid($_POST)):

                $count_users        = TblUser::find();

                self::$fname            = parent::$hit->getPost('fname', ['string', 'striptags', 'trim']);
                self::$lname            = parent::$hit->getPost('lname', ['string', 'striptags', 'trim']);

            break;

            deafult:

            break;
        }
    }
}


34.7k

I think not necessary, if you want to short this->request in HomeController

    public function RFvalidationAction($form)
    {
       $request = $this->request;
       switch($form)
        {
            case ($form->isValid($_POST)):

                $count_users        = TblUser::find();

                self::$fname            = $request->getPost('fname', ['string', 'striptags', 'trim']);
                self::$lname            = $request->getPost('lname', ['string', 'striptags', 'trim']);

            break;

            deafult:

            break;
        }


13.3k
Accepted
answer

What are you trying to optimize?

parent::$hit vs $this->request? It's 12 vs 14 chars?

So I don't think it is a good practice, IMHO.

hahahhaha yeah right @Jimmy Chandra :)



34.7k

Hey @Steven

You have tips phalcon? if you have share it on http://phalcontip.com

wow @Thien thanks this is nice, i didnt know that phalcon have this tips page or what ever u call it :) once I have done something I'll share it :)



34.7k