How to get data in function extend controller?
The solution to this problem is to just use this:
$this->load->model('notification_model');
$this->get_notification();
IronRouter extending data option on route controller
I use something similar to this in a production app:
Router.route('/test/:testparam', {
name: 'test',
controller: 'ChildController'
});
ParentController = RouteController.extend({
data: function() {
console.log('child params: ', this.params);
return {
foo: 'bar'
};
}
});
ChildController = ParentController.extend({
data: function() {
var data = ChildController.__super__.data.call(this);
console.log(data);
return data;
}
});
Using __super__
seems to do the trick!
You can than use _.extend to extend the data (http://underscorejs.org/#extend)
How to get data from a query back from the controller
model
First, make sure your model returns row. On your code you just return boolean instead of array|object of records. Therefore, you can do it like this:
Check how to generate result in codeigniter.
class View_book_model extends CI_Model {
function getBookList() {
$query = $this->db->query("SELECT * from books");
return $query->result();
}
}
controller
On your controller, store the model records on $postlist
array, in my case, I put it as book_list
for example, and pass it to your view loader.
class View_book_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('cookie');
$this->load->helper('url');
$this->load->library('session');
}
function loadView() {
$this->load->model('view_book_model');
$postlist['studentID'] = $this->input->get_post('studentID');
$postlist['book_list'] = $this->view_book_model->getBookList();
$this->load->view('viewbooks.php', $postlist);
}
}
view
In your view you can check the rows using the $postlist key as the variable name:
<? var_dump($book_list); ?>
You can generate table either manually using foreach print the HTML or using the built in HTML Table Class of codeigniter.
Add data to return of all actions in a Symfony controller
One option is to create your own base controller, and have all other controller extend it. Your base controller would override the render
function of the Controller
class from symfony framework
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class BaseController extends Controller
{
// override render method
protected function render($template, $data)
{
$commonData = [];// get data from wherever you need
parent::render($template, $data + $commonData);
}
}
Then in your other controllers
class MyAnotherController extends BaseController
{
public function fooAction() {
// ...
return $this->render('BarBundle:Foo:foo.html.twig', array('foo' => 'Foo Data'));
}
}
Related Topics
How to Access Magento User's Session from Outside Magento
Oauth Implementation in Netsuite Using PHP
How to Pass Value from One PHP Page to Another Using Session
Phpmailer - the Following Smtp Error: Data Not Accepted
How to Include a PHP.Ini File in Another PHP.Ini File
PHP - Returning the Last Line in a File
How to Correct the [Composer\Downloader\Transportexception] Error for Composer
Using Simplexml to Load Remote Url
Php: iPad Does Not Play Mp4 Videos Delivered by PHP, But If Accessed Directly It Does
Array to Object and Object to Array in PHP - Interesting Behaviour
Adding a Namespace When Using Simplexmlelement
Decrypting Strings in Python That Were Encrypted with Mcrypt_Rijndael_256 in PHP
How to Perform an Action Every 5 Results
How to Execute PHP with Extension File.Php.Jpg
PHP Get Dropdown Value and Text