I am usinf the cakeEmail fonction.
I am used to do like this (see viewVar)
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars(array('title'=>'vlaue'))
->send();
I nedd to send a lot of data as the data of several boght product. It can have one product but it can have 10 product.
Then, I would like to send an array $detailOfProducts, in that way, in my mail template, I am going to use a loop to display the content.
I tried to change like this but without success
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars($detailOfProducts)
->send();
Do you know a solution?
Thank a lot
Send them like u send the vars to your view ..
$mail->from(authComponent::user('email'))
->to($this->Session->read('Site.email'))
->subject($this->Session->read('Site.name').' : New order No. '.$this->Basket->id)
->emailFormat('html')
->template('orderconfirmation')
->viewVars(array('details'=>$detailOfProducts))
->send();
Your view code will be ..
<?php echo $detail[0]['Model']['field']; ?>
Ok, I got the answer!!!
Sorry, I should have tried before.
echo count($basketItems);
echo $basketItems[0]['name'];
then with the result of count(), I can make a loop to display all. I am going to try this now.
Many thank for you help!!!!
Here is the answer: (It's into a loop)
<?php echo $basketItems[$i]['name']; ?>
Thank for your help!!!!
Related
I need to show all moodle courses in menu listing.
Can anyone suggest me that how can I get all courses using php code or moodle inbuilt functions.
Thanks
Assuming you are writing code to be run within Moodle, you can use the get_courses() function defined within lib/datalib.php. For example:
<?php
require_once(PATH_TO_MOODLE_ROOT . '/config.php');
$courses = get_courses();
print_r($courses);
will print out a data-dump of the returned array, showing details of all the courses in your Moodle site. This example is obviously not appropriate to use on a production site!
If you check the function definition in lib/datalib.php you will see the options available for restricting the result set to particular fields or controlling the sort order.
Include this file
require_once($CFG->dirroot . '/lib/coursecatlib.php');
Use this function to get all courses in menu listing.
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true));
var_dump($allcourses);exit;
If you want to show only enrolled course to student you can use following method.
require_once($CFG->dirroot.'/blocks/course_overview/locallib.php');
global $USER,$DB;
$courses = enrol_get_users_courses($USER->id, true);
OR
If you want list all courses..
global $DB;
$query = "SELECT id, fullname, shortname from {course}";
$courselist = $DB->get_records_sql($query);
foreach ($courselist as $course) {
echo $course->fullname;
}
Thanks
i have this parsed object
$xmlObj = new SimpleXMLElement($XMLToParse, LIBXML_DOTTED_VERSION, FALSE, "http://SOME/schema/universal_v17_0");
that has the stucture like this inside it
<universal:UniversalR LocatorCode="somecode" Version="2" Status="Active">
<common_v17_0:Book Key="some" TravelerType="some">
so i can access the first element(its attributes) like this $VariableX=$xmlObj->UniversalR->attributes();//then $VariableX["Status"];
but when i want access his child i cant $tm=$xmlObj->UniversalR->Book->attributes();
it doesnt want to enter probably because of the different namespace...can any one help me . THX
I found something here http://blog.sherifmansour.com/?p=302
foreach ($xmlObj->UniversalRecord as $entry){
$namespaces = $entry->getNameSpaces(true);
$cmm = $entry->->children($namespaces['common_v17_0']);
$aa=$cmm->Book->attributes();
echo $aa["TravelerType"]."ddddd";
}
That should do it :)
$tm=$xmlObj->UniversalRecord->Book->attributes(); is this typo (UniversalRecord instead of UniversalR) only present in this post or is it also present in your code?
(I'd have liked to post this as a comment.. but it looks like i'm not allowed to, or am too stupid to find the button. :/)
I want to know how to render a comments form of a specific node in any page (ex. user profile). I've trying with drupal_get_form but it shows an error.
drupal_get_form('mytype_node_form', array('nid' => $nid));
Solutions & clues are welcome :)
First of all, you should use the proper ID of the comment form: 'comment_form' instead of 'mytype_node_form'.
The code
drupal_get_form('comment_form', array('nid' => $nid));
used to work for me in Drupal 6. In Drupal 7, function comment_form() is expecting an object parameter instead of array. This code should work for you:
$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);
Just started learning PHP today. And though I moved through most of my problems quickly, I got stumped with this one.
I have a main page page.php with a dynamic require_once to pull up content. I got the main part working, which is page.php?id=1 page.php?id=2 etc load just fine, but if somebody goes to just page.php without the ID, then there are errors that ruin the page. Now I figured out how to repress the errors with an # and I can also obviously set the links to the page to page?if=default, but I really need a solution to having page.php load content specific to it without errors. Or, perhaps, automatically redirect page.php to page.php?id=default should no id be provided.
The code I current am using for the require_once is:
<?php require_once('folder/' . $_GET['id'] . '.html');?>
Thank you for your help!
Well easiest way would be to check if you have an ID and if not, than just set default one, something like that:
$default = 1;
$id = ($_GET['id'] && is_numeric($_GET['id'])) ? $_GET['id'] : $default;
require_once('folder/' . $id . '.html');
i have a problem with calling a function which name is a string.
I made few helpers which i want to echo in my phtml file like this:
echo $this->EditProfile();
echo $this->ViewProfile();
The EditProfile() and ViewProfile() are names of the View Helpers which i created and i'm calling them in view. And this method is working fine. But when i want dynamicly call a function by name stored in database im trying to do this in this way:
im getting the names of helpers from database and store them into array and then trying to display them in foreach.
foreach ($this->modules as $key => $module)
{
echo $this->$module['name'];
}
the variable
$module['name']
contains a valid name of Helper which i want to call in phtml file (checked with Zend_debug::dump() and with just an echo $module['name'] in foeach and id display it properly... but this echo its not working and not calling the View Helper, nothing is displayed
when i try eval or call_user_func too nothing is displayed too... How can i do this in foreach or other loop?
ok solved it myself :)
dont know is this solution properly but its actually working ;)
instead call_user_func i mentioned that magical function __call is same as call_user_func_array
so i edited code like this below
foreach ($this->modules as $key => $module)
{
$this->__call($module['name'],array(null));
}
in this case array is null cause none parameters are passed to function. If in my helper ill need parameters ill pass them in this array in future.
And this solution works fine for me :)
If someone have better solution please post it here and share your opinion ;)
regards
Darek