how to call a function in codeigniter email library - codeigniter

i am using codeigniter framework. i am calling a function from controller to custome library. i want to call another function in that function.i am calling below calendarupdate() function in emailcom library.Please help me. I am trying like below.
function calendarupdate($info, $users)
{
$this->subject="Calendar Schedule Update";
$this->to='test#gmail.com';
$this->CI->email->from('support#gmail.com','test');
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
$this->CI->email->message('Hi');
$this->CI->email->set_mailtype("html");
if($this->CI->email->send())
{
$this->CI->email->clear(TRUE);
$this->newadmin($info,$newarr,$adminusers);
}}
I need to call newadmin() funtion in Emailcom library only.

If the second method you need to call is also in the emailcomm class, simply use $this->newadmin()

Related

How to load a CodeIgniter view in $promise->then() in a controller?

In my CodeIgniter 2 controller I call a model method which returns a ReactPHP promise, and I want to load a CodeIgniter view in the function called by that promise's ->then() method. How can I do this? What happens instead is the controller method returns nothing, so I get a blank page in the browser.
Here is a simplified example illustrating what I'm trying to do:
class My_class extends My_Controller {
function my_method() {
$this->my_model->returns_a_promise()->then(function ($data) {
// How can I pass the promise's resolved value to the template here?
// It seems this never gets called, because my_method() returns
// before we get here. :(
$this->load->view('my_view', $data);
});
}
}
Is there any way to tell the controller method not to send output to the browser until after the promise has resolved?
I'm not sure what are you trying to do but if you want to stop view from outputting and return it as a string then output it with echo yourself you can do this:
$view = this->load->view('my_view', $data, TRUE);
Now you have the view as a var string you can use it to do what you are trying to do.
It turns out the code in my original question does work. So the question is the answer. But the reason it wasn't working for me was that returns_a_promise() was not returning a resolved promise, so ->then() was not called and the view was not rendered. In order to make it return a resolved promise, I had to call $deferred->resolve(); in the code that returned the promise.
The upshot of this is that this code example demonstrates it is possible to run asynchronous PHP (via ReactPHP in this case) in CodeIgniter controller methods. My particular use case is to run many database queries concurrently in the CodeIgniter model.
try this:
function my_method() {
$data = array();
$data['promise'] =$this->my_model->returns_a_promise();
$data['view'] = 'my_view';
$this->load->view('my_view', $data);
}

how can i call laravel model method like modelname->save() inside the laravel view

hi i have a project in laravel 5.4 for some function i have calling the laravel model methods inside the view for my convenient so it is showing me error save() method does not exist so anyone help me is that possible to call the laravel model method inside the view or how to achieve this below is my code
below is my blade code
$pi_amount=new App\PI_Amount;
$pi_amount->invoiceNumber=$fd->invoiceNumber;
$pi_amount->total_goods=$total_goods;
$pi_amount->total_cst=$total_tax;
$pi_amount->total_security=$security_amount;
$pi_amount->freight=$freight;
$pi_amount->total_value=$total_value;
$pi_amount->save();
Make sure:
1. That is the name of the model PI_Amount
2. That it is the model on App\PI_Amount
You can import the model it using at the beginning of the php file:
use App\PI_Amount;
Hi i have create a new static function inside the Controller and call the that static method inside the view and define the process code inside the controller function so my problem resolve.
Below is my controller function
public static function processsAmount($insert_data){
$pi_amount=new PI_Amount;
$pi_amount->invoiceNumber=$insert_data['invoiceNumber'];
$pi_amount->total_goods=$insert_data['total_goods'];
$pi_amount->total_cst=$insert_data['total_cst'];
$pi_amount->total_security=$insert_data['total_security'];
$pi_amount->freight=$insert_data['freight'];
$pi_amount->total_value=$insert_data['total_value'];
$pi_amount->save();
}
and below i have make a call of that static function inside the view like
$security_amount=0;
$insert_data=array('invoiceNumber'=>$fd->invoiceNumber,'total_goods'=>$total_goods,'total_cst'=>$total_tax,'freight'=>$freight,'total_value'=>$total_value,'total_security'=>$security_amount);
echo App\Http\Controllers\PiController::processsAmount($insert_data);
so by using the above concept my problem is resolved and we can use this for further.

How to have a dynamic controller in Laravel

I'm trying to call dynamic popup views in which I need to pass the data through the controller, I want the controller to be dynamic which will access the particular function and make the view accordingly. Basically i'm looking for something like this:
Route::post('/popup/{id}', 'PopupController#{$id}');
So basically suppose when it is called like this: mydomain.com/popup/id1, it should call PopupController#id1.
Help me out with this.
You need a method that will fire the appropriate function
Route::post('/popup/{id}', 'PopupController#dispatch');
In PopupController
public function dispatch($id)
{
return $this->$id()
}
then if your $id is someFunction you need to make sure your controller has function someFunction() method
I suggest instead of writing a dynamic route or controller use switch case in controller action.
e.g.
Route::post('/popup/{id}', 'PopupController#action');
In Controller
public function action($id)
{
switch($id)
{
case 1: ...
case 2: ...
}
}

How to call a controller from another controller in codeigniter?

I want to load a controller function from another controller function using codeigniter. What is the suitable way to do this so when call it url should be changed also.
No You cant do it.
What you have to do it is create that function in model and call it through your controllers. So it will work fine.
Ex
In Model
function get_id()
{
//some argument
}
In controller 1
$this->Model_name->get_id()
In controller 2
$this->Model_name->get_id()
yes you can (for version 2)
load like this below inside your controller
$this->load->library('../controllers/whathever');
and call the following method:
$this->whathever->functioname();

Joomla 2.5 cant use $this in helper file

I have created a component and a plugin in joomla 2.5 and there is a Helper file in the component which will have many useful functions and I plan to call one of its function which then calls another function in the helper by this code:
$this->getinformation();
and it gives me this error :
Fatal error: Call to undefined method
My questions are:
Why can't I call a function in a helper in Joomla?
How can I call a function inside helper class?
Is there any class structure which i missed in this code?
Helper files are typically called statically and not using $this
First create your helper file and add methods like this:
Class myHelper {
//This method can call other methods
public static function myMethod($var) {
//Call other method inside this class like this:
self::myOtherMethod($var);
}
//This method is called by myMethod()
public static function myOtherMethod($var) {
//Put some code here
}
}
Simply include the helper file like this in the documents that you would to use it:
require_once JPATH_COMPONENT.'/helpers/my_helper.php';
Then use it like this:
myHelper::myMethod($var);
or
myHelper::myOtherMethod($var);
You have to include the helper file and call the function using the classname
Add the following line in the plugin or component:
jimport( 'joomla.filesystem.folder' );
require_once JPATH_ROOT . '/components/com_xxxx/helper.php';
classname::functionname();
OR
If you are working on the same helper file means then call like this
classname::functionname();

Resources