I am trying to implement the CI Asset manager found here. After I placed the files in the correct locations and then tried to call the assets in my main view I get the following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$assets
Filename: index/index.php
Line Number: 18
What am I forgetting to do that is causing this error?
Line 16-18 are
$this->load->library("Assets");
echo $this->assets->load("ie10mobile.css", "Content");
You have to load library and use it in controller file, not the view.
Sample controller function:
function index()
{
$this->load->library("assets");
$this->data['css'] = array(
$this->assets->load("ie10mobile.css", "Content"),
$this->assets->load("style.css", "Content"),
$this->assets->load("custom.css", "Content")
);
$this->load->view('index_view', $this->data);
}
Sample view file: index_view.php
foreach ($css as file) {
echo $file;
}
Related
I'm stuck in this error. Can someone help me out? I am using Codeigniter 3.1.10
Here's a snippet of my code in system/core/Common.php
function &load_class($class, $directory = 'libraries', $param = NULL)
{
static $_classes = array();
// Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
return $_classes[$class];
}
$name = FALSE;
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
foreach (array(APPPATH, BASEPATH) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = 'CI_'.$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once($path.$directory.'/'.$class.'.php');
}
break;
}
}
I keep on receiving this error message:
Notice: Only variables should be passed by reference in
/customers/5/d/b/tsoft.se/httpd.www/kanban/system/codeigniter/Common.php
on line 148
A PHP Error was encountered Severity: Notice
Message: Only variables should be passed by reference
Filename: codeigniter/Common.php
Line Number: 148
**Note : Line 148 is this return $_classes[$class];
As stated in a comment on this github issue, since you are using CodeIgniter version 3.1.10, you need to replace your system folder.
The file system/codeigniter/Common.php has been moved to system/core/Common.php on your version.
I got my library from
http://biostall.com/codeigniter-google-maps-v3-api-library
and followed the instructions in
http://biostall.com/demos/google-maps-v3-api-codeigniter-library/
but i am receiving an error message
A PHP Error was encountered
Severity: 8192
Message: Methods with the same name as their class will not be constructors in a future version of PHP; Googlemaps has a deprecated constructor
Filename: libraries/Googlemaps.php
Line Number: 16
Backtrace:
File: C:\xampp\htdocs\test_map\application\controllers\Welcome.php
Line: 25
Function: library
File: C:\xampp\htdocs\test_map\index.php
Line: 292
Function: require_once
Anyone knows how to solve this problem?
Try with renaming
function Googlemaps($config = array())
{
if (count($config) > 0)
{
$this->initialize($config);
}
log_message('debug', "Google Maps Class Initialized");
}
to
function __construct($config = array())
{
if (count($config) > 0)
{
$this->initialize($config);
}
log_message('debug', "Google Maps Class Initialized");
}
If doesn't work, than library probably needs more code changes since it is code older than 2-3 years.
You need to change the name of class with CI_Googlemaps and the name of constructor with __construct
Trying to crate objects dynamically for a plug in system (work in progress)
heres my code using $this->module->load_module('test'); to use the method that creates the dynamic objects. Following code is the function that loads the class's and makes use of an auto loader, i have checked that its getting the correct file etc.
<?php
class BaseModule {
function __construct() {
}
function load_module($module){
echo 'Module = '.$module.'<br />';
$object_name = $module . "Controller";
$this->$$module = new $object_name();
}
}
Here is a test module that it would load when invoking $this->module->load_module('test'); and it creates the object outputting the test strings via echo statements. Heres the code for the test module that was constructed. Which should cause no problems as there is not really a solution but just an output string, but posted any way.
<?php
class testController {
function __construct() {
echo 'test controller from modules <br />';
}
}
However when running the page i am getting some errors can any one help out?
Notice: Undefined variable: test in
/Applications/MAMP/htdocs/tealtique/application/modules/BaseModule.php on line 11
Fatal error: Cannot access empty property in
/Applications/MAMP/htdocs/tealtique/application/modules/BaseModule.php on line 11
In CodeIgniter I'm try to made header with code from DB, my controller code:
public function index()
{
$this->load->model('main_model');
$data['result'] = $this->main_model->get_tipsters();
$this->load->view('template/header_view',$data);
}
And header_view:
<?php foreach($result->result() as $row): ?>
<div id="tipster"><img src="<?=$row->photo;?>" /><br /><?=$row->name;?></div>
<?php endforeach; ?>
Header work's only It self view file, but not In others pages.
I Including header like this in controllers:
$this->load->view('template/header_view');
$this->load->view("/bets/index",$data);
$this->load->view('template/footer_view');
Getting this error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: result
Filename: template/header_view.php
Line Number: 14
Fatal error: Call to a member function result() on a non-object in /home/user/domains/test.com/public_html/application/views/template/header_view.php on line 14
Line 14 is foreach, I have copied early.
Since your header view file is always expecting $result, you'll need to provide it for all your controller methods:
$this->load->model('main_model');
$data['result'] = $this->main_model->get_tipsters();
$data['main'] = $this->main_model->get_main_data(); //example
$this->load->view('template/header_view',$data);
$this->load->view("bets/index",$data);
$this->load->view('template/footer_view');
This can become cumbersome, so consider creating a MY_Controller file that extends CI_Controller - more about that here.
You can make a function in your Common_model
for fecthing result on your header file.
and directly get result from that function by calling it in a view file.
common_model.php
function your_function()
{
// code for fetching data for header
/// return your result here
}
call directly this function in a view file as
$rs = $this->Common_model->your_function();
Note: common_model is load by default .if disable then you need to load model in a view file.
Best way to load CI object on view element file(header_view) and load and call model method with CI object
$CI = & get_instance()
$CI->load->model('main_model');
$result = $CI->main_model->get_tipsters();
<?php foreach($result->result() as $row): ?>
<div id="tipster"><img src="<?=$row->photo;?>" /><br /><?=$row->name;?></div>
<?php endforeach; ?>
and remove code from controller
Hi i am trying to call a model from view but i am getting error as.
A PHP Error was encountered Severity: Notice Message: Undefined property:
CI_Loader::$Stopsmap_Model Filename: stopsmap/index.php Line Number: 59
i tryed this below code in view.But no luck
foreach ($routes as $route_details):
//calling model
//$trip_max_min_sequence_details = $this->load->Stopsmap_Model->fullTripdetails($trips->trip_id); i tried this also but same error
//$this->load->model('Stopsmap_Model');
//$data = $this->stopsmap_model->fullTripdetails($route_details->route_id); i tried this also but same error
$this->load->model('fixedtransit_model/Stopsmap_Model');
$get_route_related_trips = $this->Stopsmap_Model->getRoutetrips($route_details->route_id);
if(count($get_route_related_trips)>=1):
echo '1 stop';
endif;
endforeach;
thanks in advance for the help
In your controller , you can have like this:
function routes(){
//call model
$this->load->model('fixedtransit_model/Stopsmap_Model');
$routes = $this->topsmap_model->get_routes();
foreach ($routes as $route_details){
$get_route_related_trips[] = $this->Stopsmap_Model->getRoutetrips($route_details->route_id);
}
$data['related_routes'] = $get_route_related_trips;
//load view and pass data
$this->load->view('myview' , $data);
}
and in your view:
<?php foreach($related_routes){
//do something
}
?>
on my end
i have created a model named accountmodel in applications/models dir
and load in view like (would be best if you load model in your controller):-
$this->load->model('AccountModel','Account');
//AccountModel (model class name)
//Account (object) you can further use this model using object
for more info :- http://ellislab.com/codeigniter/user-guide/general/models.html