CodeIgniter Forums

Full Version: Using external class in my Controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im working on my first project in CodeIgniter and I wonder How can I use my class from library in my Controller.

libraries/Twitterclass.php:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Twetterclass {

public function 
__construct($hashtag$tweet_id)
{
 
   require_once('TwitterAPIExchange.php');

 
   //There is my working code

 
   //I want to make use of this $n in my Controller
 
   return $n;

}
}

/* End of file Twetterclass.php */ 

My Controller:

PHP Code:
public function microtweets()
 
   {
 
       $params = array('hashtag' => 'somehashtag''tweet_id' => '673899616799191040');
 
       $data['count_tweets'] = $this->load->library('Twetterclass'$params);

 
       $this->load->view('tweets'$data);
 
   


I want to use his extended class in my controller and work there on this $n value or for example display it in my View.


I got few errors in my view for example:

Quote:A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Twetterclass::__construct(), called in /coinmonitor/system/core/Loader.php on line 1246 and defined
libraries/Twitterclass.php defines a class Twetterclass? The names need to match.
(12-08-2015, 03:58 AM)lipa Wrote: [ -> ]Im working on my first project in CodeIgniter and I wonder How can I use my class from library in my Controller.

libraries/Twitterclass.php:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Twetterclass {

public function 
__construct($hashtag$tweet_id)
{
 
   require_once('TwitterAPIExchange.php');

 
   //There is my working code

 
   //I want to make use of this $n in my Controller
 
   return $n;

}
}

/* End of file Twetterclass.php */ 

My Controller:

PHP Code:
public function microtweets()
 
   {
 
       $params = array('hashtag' => 'somehashtag''tweet_id' => '673899616799191040');
 
       $data['count_tweets'] = $this->load->library('Twetterclass'$params);

 
       $this->load->view('tweets'$data);
 
   


I want to use his extended class in my controller and work there on this $n value or for example display it in my View.


I got few errors in my view for example:

Quote:A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Twetterclass::__construct(), called in /coinmonitor/system/core/Loader.php on line 1246 and defined

The Tweeterclass::__construct should be
PHP Code:
public function __construct($params) {
 
   // ...


Read more here