Build a PHP MVC Application: Models (Part 6/9)

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

You should make that function model inside the Controller class protected. At the moment you could go to and it'll call that function. You can easily prevent this by making that function protected.

maxverb
Автор

If you get an error with $this->model('User'), try parent::model('User');

thehumblestudent
Автор

Where is the base controller (core/Controller.php) instantiated?

saburius
Автор

It would be more clear if you had used namespaces. This because it is impossible in your tutorial to create a controller user and load the model user in the user controller. PHP will give a fatal error because the name is allready in use.

Thanks anyway for your tutorial :)

EDIT: whoops just noticed that this tutorial is from 2014

youri
Автор

What is public $name; for? It all works OK without it. Is that because the $user->name is set in the controller?

CyanidePierce
Автор

sir last question.
receive data by return $data= $con->quiry("select * from <<table>>"); in model
how to bring it into view and manipulate into <table></table>

Dawar
Автор

I'm making a login/reg system but i don't know how, with mvc. I've done it procedurally in the past. I don't understand why I need the model. I have a controller called load, which contains a function. The function's name is register. I then use the view function, which is added in a later vid and is in the core controller, to point to my view called register. I add my form and then use procedural code in the view file. But I'm trying to understand why I should use a model instead of the current method. Also, I would like to know how to get POST data from my form and insert it to the db, using a model, not procedural code in the view.

TheTopgun
Автор

oh one more question :) how come we were able to create an object from '$this->controller = new $this->controller;'? Shouldn't it include parentheses at the end? Like the example in this video 'return new $model();'? what gives?

majmunskaposla
Автор

getting an error

Hello
Notice: Undefined index: name in ...\system\App\views\Home.php on line 1

kamandejohn
Автор

How do you parse arguments to the constructor of the model you've added?

paulb
Автор

Guys please help me. I have a lot of questions and makes me so confuse, but why I have to *return new $model(); ?* I tried to remove that line and then showed up an error *Creating default object from empty value.* But it still show me the param. And why when I tried to remove the *()* in the return new $model(); It doesn't giving any errors?

I'm new at this, please help me. Really confusing. Thank in advance.

permanar_
Автор

my route includes public/home/index ..., why is public include?, i have all step done, but i dont know why public is the first element of array t_T

catsit
Автор

So what happens is a model and controller have the same name or declaration?

CristinaDandy
Автор

Why am i supposed to use
$this->controller = new $this->controller
To make it possible to use a method of the parent class inside my child class? Without it it gives me an error of using $this while not in object context but when calling the function in the extended class I am supposed to be in object context right? Can anyone explain this to me please.

randomdude
Автор

Warning: Creating default object from empty value in line 8 home.php $user->name ="Alex"; how fix it

sawomircieslar
Автор

When does the individual controllers (home.php) instantiated? In the code, it only requires the controller's file, does it instantiate automatically?

loulamperouge
Автор

How to pass get variables in the url and receive it ? ex: home.com/index?need=123

guruzone
Автор

Hey. Could you use smarty or twig in view controller ?

dariuszwojcikowski
Автор

@ 1m46s with $this->model('User');
i am getting this error:
"PHP Fatal error:  Using $this when not in object context "
and my page is not echoing out 'User'
can anyone help?

zims