Error after making virtual host - php

I have a project developed in Codeigniter. It works fine when I try to access it on the browser at localhost using localhost/bmlivenew. But after making its virtual host, when I access it on the browser using www.bmlivenew.com , it displays the website but at the top of it, it shows an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: designer_images
Filename: controllers/Designs.php
Line Number: 42
Backtrace:
File: /var/www/html/bmlivenew/application/controllers/Designs.php
Line: 42
Function: _error_handler
File: /var/www/html/bmlivenew/index.php
Line: 324
Function: require_once
Whereas, the variable $designer_images is properly defined and it does not throw such an error if I try to access the website using localhost/bmlivenew.
Bunch of codes where I have defined the $designer_images in the Designs controller.
$designers = $this->interior_images_m->get_by($cond);
foreach ($designers as $key => $designer) {
$designer_images = $this->interior_new_m->get_by(array('id'=>$designer->name));
$designers[$key]->images = $designer_images;
}
$this->data['names'] = $designer_images;
$this->data['designers'] = $designers;
// Load View
$this->load->view("frontend/ourdesign",$this->data);
Any help is welcome.

Hope this will help you :
initialise $designer_images first, above foreach loop
Should be like this :
$designers = $this->interior_images_m->get_by($cond);
$designer_images = NULL;
foreach ($designers as $key => $designer)
{
$designer_images = $this->interior_new_m->get_by(array('id' => $designer->name));
$designers[$key]->images = $designer_images;
}
$this->data['names'] = $designer_images;
$this->data['designers'] = $designers;

Related

A PHP Error: Only variables should be passed by reference in Codeigniter

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.

Codeigniter 'Message: Undefined index: site_lang' issue at first load

I have developed a website and it is working fine in my localhost.
But I wanted to test it in a local area network before going live.
There is an issue I am facing which is at first load in a browser or any other machine it shows below error until I change the language once. When I change the language once then the issue is never happening again.
I am new and this is my first project so can anyone help me in this regard.
Thanks in advance
A PHP Error was encountered
Severity: Notice
Message: Undefined index: site_lang
Filename: models/companies.php
Line Number: 15
Backtrace:
File: C:\xampp\htdocs\fp\application\models\companies.php
Line: 15
Function: _error_handler
File: C:\xampp\htdocs\fp\application\controllers\home.php
Line: 19
Function: get_companies
File: C:\xampp\htdocs\fp\index.php
Line: 315
Function: require_once
Here is my Model:
//---- Table Companies ---
public function get_companies()
{
// Retrieve titles for all languages
$sql = "SELECT * FROM `ci_companies` WHERE `co_id` = 1";
// Retrieve appropriate title according to the chosen language in the system
$sql = "SELECT `co_id`, `co_name`, SUBSTRING(`co_detail`,1,100) AS `co_detail`, `co_img`, `co_img2` FROM `ci_companies` WHERE `co_lang` = '".$_SESSION['site_lang']."'";
$query = $this->db->query($sql);
return $query->result();
}
And here is my controller:
function switchLang($language = "") {
$language = ($language != "") ? $language : "english";
$this->session->set_userdata('site_lang', $language);
redirect($_SERVER['HTTP_REFERER']);
}
Try like this.error due to wrong use of single quotes.
$language = $this->session->userdata('site_lang');//or $_SESSION['site_lang']
$sql = "SELECT `co_id`, `co_name`, SUBSTRING(`co_detail`,1,100) AS `co_detail`, `co_img`, `co_img2` FROM `ci_companies` WHERE `co_lang` = '{$language}'";

When registering a new account on my site this error pops up. Everything else works fine

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/Email_model.php
Line Number: 187
Backtrace:
File: /public_html/application/models/Email_model.php Line: 187
Function: _error_handler
File: public_html/application/controllers/Home.php Line: 1409
Function: send_code_sms
File: /public_html/index.php Line: 292 Function: require_once
Controller:
if ($this->input->post('password1') == $this->input->post('password2')) {
$password = $this->input->post('password1');
$data['password'] = sha1($password);
$this->db->insert('vendor', $data);
$this->email_model->account_opening('vendor', $data['email'], $password);
$id = $this->db->insert_id();
*$this->email_model->send_code_sms('vendor', $id);*
echo 'done';
}
Model:
//email_verify
function send_code_sms($type,$id){
$code = $this->db->get_where($type,array($type.'_id' => $para2))->row()->sms_code;
*$phone = $this->db->get_where($type,array($type.'_id' => $para2))->row()->phone;*
$text = translate('your_verification_code_is')." : ".$code;
$this->do_sms($phone,$text);
}
View:
require_once BASEPATH.'core/CodeIgniter.php';
I am having this error on my site. I Sent an email to my developer to fix the errors causing my customers to be unable to register accounts but I have not received any replies in 5 days. The sms verification feature is not supposed to used yet because of no api. So the only thing supposed to be working is email verification. Whenever someone tries to register, the error above appears.
Need Help. Thanks
(There is an asterisk to indicate the line with the error)

How to pass an array to the main view in Codeigniter

It seems that I just can't pass an array in another function into main view.
My index() function is =>
public function index()
{
$this->load->view('anasayfa');
}
My aforementioned function is =>
public function pozisyon_tutma()
{...
....
print_r(array_values($pozisyon));
$GLOBALS['pozisyong'] = $pozisyon;
}
which works...
I am seeking something like =>
public function index()
{
$this->pozisyon_tutma();
$data['hoppa']=$GLOBALS['pozisyong'];
$this->load->view('anasayfa', $data);
}
and I am seeking in view 'anasayfa' (which is the main view) something like this code to work=>
<?php
print_r(array_values($hoppa));
?>
However this code gives the following error=>
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: hoppa
Filename: views/anasayfa.php
Line Number: 19
Backtrace:
File: D:\wamp\www\proje\application\views\anasayfa.php
Line: 19
Function: _error_handler
File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 24
Function: view
File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: array_values() expects parameter 1 to be array, null given
Filename: views/anasayfa.php
Line Number: 19
Backtrace:
File: D:\wamp\www\proje\application\views\anasayfa.php
Line: 19
Function: array_values
File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 24
Function: view
File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
All help will be much appreciated. I checked all other threads in stackoverflaw and could not make any of them work in my case... Thank you all
You should use in your controller:
$data = array('key1'=>$value1, 'key2'=>$value2, 'key3'=>functionX()....);
$this->load->view('yourview.php',$data);
And in the view to access to the array of values:
echo $key1; // prints $value1.
echo $key2; // prints $value2.
Also, you could use $_SESSION to store some variables in CI. Hope it helps.
I did it in the following way=>
public function index()
{
require('Hesaplama.php');
$Hesaplama = new Hesaplama();
$data['hoppa']=$Hesaplama->pozisyon_tutma();
$this->load->view('anasayfa', $data);
}
It works. I returned $pozisyon which is an array as #mic suggested. I will keep the suggestions of #JP. Aulet in case I need them in the near future. Thank you all...

Asset Library not loading correctly

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;
}

Categories