creating web services for iphone and cakephp project - iphone

Is there any way to collaborate Cakephp project with Iphone. Like: retrieving json data with cakephp models as WebServices in iphone. The aim behind this question is to use the cakephp code rather then creating WebServices differently.
Your help will be appreciated, Thanks!

Cakephp is a framework that outputs json data as much as like any other php frameworks out there.
You have to write functiosn like there:
public function api_get_release_tracks($release_id = null) {
if($release_id) {
$tracks = $this->Track->find('all', array( //sql queries are better here
'fields' => array('id', 'name', 'duration', 'duration_str',
'sample_audio', 'price', 'local_price'),
'conditions' => array('release_id' => $release_id),
'order' => array('position ASC')
));
$this->set('tracks', $tracks);
$this->set('_serialize', 'tracks');
}
}
Then you can get the json output in this url:
http://localhost:8090/{api name in cofig}/{controller name}/{things after api_ in function name}/{input parameters}.json
read more in here
Also you can alter the routing to change the name
api
to anything in
Configure::write('Routing.prefixes', array('master', 'api'));
in core.php in app/config

Related

SugarCRM Mass removal of custom fields

I have a few hundred custom fields to delete in an older version of SugarCRM. Is very labor intensive to delete through web interface...
Can this be done directly by deleting files in the instalation (vardefs, anything else?)
This is similar to [question asked earlier] (revert the custom fields made by sugarCRM), but was solved by using web interface for a few fields.
I can easily write a script then to remove the fields from the {table_name}_cstm tables...
You can try something like that (should be execute in a SugarCRM environment like an entryPoint and with an admin user)
$fieldsByModule = array(
'Accounts' => array(
'field_1_c',
'field_2_c',
),
'Contacts' => array(
'field_1_c',
'field_2_c',
),
);
require_once('modules/DynamicFields/DynamicField.php');
foreach ($fieldsByModule as $moduleName => $fields) {
foreach($fields as $field){
$dyField = new DynamicField();
$dyField->bean = BeanFactory::getBean($moduleName);;
$dyField->module = $moduleName;
$dyField->deleteField($field);
}
}
Live coding without test the code but the core of the process should be near like that.

Zend_Navigation_Page and onclick attribute?

I've been asked to add some Google event tracking to a link on a site I'm 'fixing'.
This relies on the 'onclick' attribute and the ZEND framework (1.11.11) application seems to generate those links as described below.
I can't find out how to add custom attributes to this function, specifically, 'onclick'.
Is this even possible? I've never got along with Zend and any gurus out there will probably know far better than I if it's even possible.
/**
* #return Zend_Navigation_Page_Uri
*/
public function getBrochurePageUri()
{
return new Zend_Navigation_Page_Uri(array(
'label' => 'Brochure request',
'uri' => 'http://www.website.com/brochure/'
)
);
}
try adding the following:
'attribs' => array('onclick'=>'somefunction(params)')
resulting in the following:
return new Zend_Navigation_Page_Uri(array(
'label' => 'Brochure request',
'uri' => 'http://www.website.com/brochure/',
'attribs' => array('onclick'=>'somefunction(params)')
)
);

How to make own frontend-Forms with Magento 1.6.2

I have make a little Extension for Magento 1.6.2. I managed to write code in the backend-system to create a EAV Model to the database and I can write/read items from it like this tutorial: http://www.pierrefay.com/magento-admin-gridview-85
How can I use the following Forms in the frontendsystem, .. I have see there are dont classes like Mage_Adminhtml_Block_Widget_Form. I dont want to use own HTML constructions, want to get I want Magento look and feel. Have anyone a idea how to make own forms in magento frontend with magento classes?
class Extension_Name_Adminhtml_Printcatalog_Edit_General_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('printcatalog_form',
array( 'legend' => __('Allgemeine Informationen')));
$fieldset->addField('catalog_name', 'text',
array(
'label' => __('Katalogname'),
'class' => 'required-entry',
'required' => true,
'name' => 'catalog_name',
));
$fieldset->addField('release_date', 'text',
array(
'label' => __('Erscheinungsdatum'),
'class' => 'required-entry',
'required' => true,
'name' => 'release_date',
// 'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'/adminhtml/default/default/images/grid-cal.gif',
// 'format' =>
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
));
if (Mage::registry('printcatalog_data'))
{
$form->setValues(Mage::registry('printcatalog_data')->getData());
}
return parent::_prepareForm();
}
}
?>
Not possible out of the box, all magento front-end forms are hard coded. As you can see in the class you provided it is part of the Adminhtml module (Mage_Adminhtml_Block_Widget_Form), which is for the administration dashboard within magento.
The amount of development to integrate a form class like in your code is not worth the time or flexibility of a hardcoded front-end form ... in most cases. If the majority of your continued development revolved around forms, then I'd reconsider building out abstract form classes to help in the creation of your forms via the controller.
On a higher note, Magento does provide a fairly decent javascript validation system for your front-end.
You should look into Zend_Form, which came around after Magento/Varien's original form implementation.

Zend Framework: Need help setting up Routing

how do i set up routing as follows
these work with the standard routing
/posts => index action (listing)
/posts/view => view action (individual post)
/posts/add => add action
/posts/edit => edit action
what abt these?
/posts can by filtered based on 1 or more query strings, in any order. eg.
/posts/tagged/tag1
/posts/tagged/tag1/timeframe/1w => fyi. 1w means 1 week
/posts/timeframe/1w/tagged/tag1 => can be in any order
/posts/sortby/dtposted => more options maybe added
how can i handle these? i tried
$route = new Zend_Controller_Router_Route(
'posts/*',
array(
'controller' => 'posts',
'action' => 'index'
)
);
$router->addRoute('postsIndex', $route);
but of cos, all routes to posts/* goes to the index controller. not what i want
You dont need to use a route for those url's if your using proper naming conventions it should naturally.
class PostsController extends Zend_Controller_Action{
public function viewAction(){
}
public function editAction(){
}
public function addAction(){
}
public function indexAction(){
}
}
I suggest going back to basics and learning how controllers models and views work in the zend framework before trying to understand routing :)

Zend Sessions getting mixed up

I'm currently working on the login for a Zend Framework application, and I'm using a combination of Zend_Auth and Zend_Session using a database adapter (as described in the Zend Framework manuals).
I've made a resource for the session:
class DC_Resource_DbSession extends Zend_Application_Resource_ResourceAbstract{
public function init(){
}
public function setadapter($value){
$this->dbAdapter = $value;
}
public function setSession($adapter){
//put your code here
$config = array(
'name' => 'sessions',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime',
'db' => $adapter
);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
Zend_Session::setOptions(array('name'=>'MY_SESSION_NAME'));
Zend_Session::start();
}
}
Zend Auth then uses the session to store some rudimentary authentication information.
However, when testing the login (from the same IP) if one user in our office logs in and another user goes to the site, they are logged in as the user!!! Can anyone help me figure out why they are using each other's sessions?
DOH!!!!
My humble, humiliated apologies. The id column datatype had been set to INT by our migrations guy - and obviously it needs to be VARCHAR....
smacks self in face...