CodeIgniter class loading is not working - codeigniter

I have a class in application/library folder - filename = person_struc.php and the code is following..
class Person_struc {
var $person_id;
var $person_name;
public function set_info($person_id, $person_name) {
$this->person_id = $person_id;
$this->person_first_name = $person_name;
}
}
I have a view (person_list.php) and want to load the class by as follows -
$this->load->library('person_struc');
$this->person_struc->set_info(1,"xxx");
I have controller (person) and model (person_model). But it is generating error..
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$person_struc
Filename: person/person_list.php
Fatal error: Call to a member function set_info() on a non-object in
I tried to solve the problem but failed. Do you have any solution please...

Initial letter of your file name must be capital. In your case it would be filename = Person_struc.php instead of filename = person_struc.php

Try like
class Person_struc extends CI_Controller

your class must be locate in library.
your class name and file name are same.
and your person_list controller must be extends CI_CONTROLLER

Related

Can't call method from URL when super class is REST_Controller, codeigniter

I want to run URL from browser and get file content located out of my project, for example: /home/fessy/file.txt
I use codeigniter and doctrine.
I have a method:
class Api extends REST_Controller {
// ....
public function get_file_content_get(){
var_dump(array('ftp_path' => $this->uri->segments));
$name = $this->uri->segment(3);
$rootPath = $this->uri->segment(4);
$file = file_get_contents("$rootPath/$name.txt", FILE_USE_INCLUDE_PATH);
// $this->_response('success', array('file_contents' => $file));
}
So I generate my URL as:
site.com/index.php/api/get_file_content_get/118130/%2Fhome%2Ffessy%2Ffile.txt
But I get an error:
<xml>
<status/>
<error>Unknown method.</error>
</xml>
When I change super class from REST_Controller to CI_Controller I succeeded to call get_file_content_get method.
I event can't get site.com/index.php/api/get_file_content_get/ to call the index()
What I'm doing wrong?
thanks,
Found the issue:
I need to remove _get postfix since Doctrine uses this postfix as GET indicator
Instead:
site.com/index.php/api/get_file_content_get/118130/%2Fhome%2Ffessy%2Ffile.txt
should be:
site.com/index.php/api/get_file_content/118130/%2Fhome%2Ffessy%2Ffile.txt

DB::query() Error "Class 'Model\DB' not found"

Hi I'm kinda new to FuelPHP and right now I'm studying some syntax on how to retrieve data using DB::query() builder and I have encountered an error using this code.
Controller:
use \Model\Welcome
class Controller_Welcome extends Controller
{
public function action_index()
{
print_r(Welcome::getuser());
}
}
Model:
namespace Model;
class Welcome extends \Model {
public static function getuser()
{
$query = DB::query("SELECT * FROM `users`");
return $query->execute();
}
}
And it keeps prompting an error saying "ErrorException [ Fatal Error ]:
Class 'Model\DB' not found" what does it mean by 'Model\DB' not found? what did I miss? or what is missing with my code?
And I already configured the database settings on the /config/development/db.php
Your help is much appreciated.
Thanks in advance.
The DB class is the in global namespace while your model is in the Model namespace so unless you import DB with a use statement you will have to specify a \ before the class name \DB::query().
If you do not do either of these then PHP will try and load the DB class from the Model namespace.

Fatal error: Cannot use object of type stdClass - amfphp

I am newbee for Amfphp+codeignitor, I am unable to see the answer for the question amfphp 2.2, index.php gives fatal error?, Or it is not clear to me.
I followed the process mentioned here
http://www.nunomira.com/blog/2012/03/codeigniter-2-0-3-with-amfphp-2-0/
I am getting the same error - Fatal error: Cannot use object of type stdClass as array in D:\vhosts\site\application\libraries\Amfphp\Plugins\AmfphpMonitor\AmfphpMonitor.php on line 167
No Idea where i am doing the mistake.
http://localdomain.com/index.php/amf/gateway is the url i am trying.
How to rectify? what is the problem? if the problem is resolved, will i look service browser?
Experts please guide me on this...
Here is the code
Folder Structure
-controllers
-amf
-services
-Testservice.php
-Gateway.php
-libraries
-Amfphp (Amfphp folder)
Gateway.php
<?php
require_once APPPATH . "/libraries/Amfphp/ClassLoader.php";
class Gateway extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$config = new Amfphp_Core_Config();//do something with config object here
$config->serviceFolders = array(dirname(__FILE__) . "/services/");
$gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway($config);
$gateway->service();
$gateway->output();
}
}
Testservice.php
<?php
class Testservice extends CI_Controller {
public function getMessage()
{
return array("param1" => "param1");
}
}
Thanks
someone pointed out a similar problem and a fix has been made but not released yet. Could you try replacing your AmfphpMonitor.php code with this one?
https://github.com/silexlabs/amfphp-2.0/blob/master/Amfphp/Plugins/AmfphpMonitor/AmfphpMonitor.php

CodeIgniter Undefined Variable while trying to create subview

Hi I am new to CodeIgniter and am taking a tutorial. I ran into an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subview
Filename: admin/_layout_modal.php
Line Number: 7
An Error Was Encountered
Unable to load the requested file: .php
I followed the tutorial to the tee and I cant seem to find out where I am going wrong.
here is the controller
<?php
class User extends Admin_Controller {
public function __construct() {
parent::__construct();
}
public function login() {
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}
}
and the view
<?php $this->load->view($subview); ?>
Please help...
If you gave script from your .php file not tutorial then everything is ok.
You are probably typing the wrong url in when you try to access the page. Make sure you are loading "admin/user/login" instead of "admin/dashboard/modal".
If you are following tutplus tutorial- building cms with codeigniter, First watch two episodes, Managing User Part 1 and Managing User Part 2 and then Start building, Your question will be answered on Part 2.... the dashboard has to declare the subview variable and
CREATE THAT admin/dashboard/index.php file in views
class Dashboard extends Admin_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->data['subview'] = 'admin/dashboard/index';
$this->load->view('admin/_layout_main',$this->data);
}
public function Modal(){
$this->load->view('admin/_layout_modal',$this->data);
}
}
don't need to pass data to $this. Just pass the data to
$data['variable_name']=data;
pass this $data variable to view through load class.

model inheritance error in codeigniter

I am trying the following code but keep getting the this error:
PHP Fatal error: Call to undefined method
news_model::get_db_message()
in my application/core/My_Model.php
class MY_Model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function get_db_meesage() {
echo "bla";
}
}
this is my news_model.php
class news_model extends MY_Model {
public function __construct()
{
parent::__construct();
}
public function delete_news($news_id) {
$this->get_db_message();
}
}
I felt it is probably a very subtle error but I just can't figure this out..
Correct answer taken from comments.
Codeigniter expects classes to start with a capital letter. This is stated in their General Style and Syntax document.
To quote:
Class and Method Naming
Class names should always start with an
uppercase letter. Multiple words should be separated with an
underscore, and not CamelCased. All other class methods should be
entirely lowercased and named to clearly indicate their function,
preferably including a verb. Try to avoid overly long and verbose
names.
INCORRECT: class superclass , class SuperClass
CORRECT: class Super_class
public function get_db_meesage() {
echo "bla";
}
PHP Fatal error: Call to undefined method news_model::get_db_message()
get_db_message()
get_db_meesage()

Resources