Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by wojsza » Mon Sep 10, 2012 11:52 pm
I have a problem, Ive been making my own MVC app but there seems to be a problen in passing variables between model and controller. Output from controller is a single variable containing some json format data and it looks simple.
Controller
- Code: Select all
class controllerLib
{
function __construct()
{
$this->view = new view();
}
public function getModel($model)
{
$modelName = $model."Model";
$this->model=new $modelName();
}
}
class controller extends controllerLib
{
function __construct()
{
parent::__construct();
}
public function addresses($arg = false)
{
echo'Addresses '.$arg.'<br />';
$this->view->render('addressesView');
$this->view->showAddresses = $this->model->getAddresses();
}
}
View
- Code: Select all
class view
{
function __construct()
{
}
public function render($plik)
{
$render = new $plik();
}
}
class addressesView extends view
{
public $showAddresses;
function __construct()
{
parent::__construct();
require 'view/head.php';
$result = $this->showAddresses;
require 'view/foot.php';
}
}
-
wojsza
- New php-forum User

-
- Posts: 1
- Joined: Mon Sep 10, 2012 11:24 pm
by Jeroen » Tue Sep 11, 2012 7:43 am
You set the variable AFTER you do the output
- Code: Select all
public function addresses($arg = false)
{
echo'Addresses '.$arg.'<br />'; //Why output in your controller?
$this->view->showAddresses = $this->model->getAddresses(); //Where is this method in your code? And you better create a method to set "showAddress" instead of using a public variable.
$this->view->render('addressesView');
}
-
Jeroen
- New php-forum User

-
- Posts: 40
- Joined: Fri Aug 10, 2012 4:37 pm
-
by Acesystech » Thu Sep 13, 2012 11:51 pm
-
Acesystech
- New php-forum User

-
- Posts: 35
- Joined: Mon Aug 20, 2012 10:27 pm
- Location: Ernakulam
-
Return to PHP coding => General
Who is online
Users browsing this forum: No registered users and 1 guest