1) Configurando APP Controller cd src/cake/app/plugins/NOME_DO_SEU_PLUGIN
gedit NOME_DO_SEU_PLUGIN_app_controller.php
Adicione o seguinte codigo
<?php
class NOME_DO_SEU_PLUGINAppController extends AppController {
var $layout = 'NOME_DO_SEU_PLUGIN';
var $layoutScheme = 'NOME_DO_SEU_PLUGIN';
var $componets = array(
'Typhographer.TypeLayoutSchemePicker'
);
var $helpers = array(
'Typhographer.TypeDecorator' => array(
'name' => 'StyleFactory',
'receive_automatic_class' => true,
'receive_tools' => true,
'generate_automatic_classes' => false
),
'Typhographer.*TypeBrickLayer' => array(
'name' => 'Bl',
'receive_tools' => true
),
'JjUtils.Jodel',
'Corktile.Cork' // Utilizado Para o Contente Stream
)
function beforeRender() {
parent::beforeRender();
$this->TypeLayoutSchemePicker->pick('NOME_DO_SEU_PLUGIN');
}
function beforeFilter() {
parent::beforeFilter();
StatusBehavior::setGlobalActiveStatuses(array(
'publish_status' => array(
'active' => array(
'published'
),
'overwrite' => true,
'mergeWithCurrentActiveStatuses' = true
)
));
}
}
Lebrece que não e nescessario feichar o php.
2) Configurando APP Model
gedit NOME_DO_SEU_PLUGIN_app_model.php
Adicione o seguinte codigo
<?php
class NOME_DO_SEU_PLUGINAppModel extends AppModel {
var $actsAs = array('Containable');
}
3) Agora vamos criar o php dentro da pastas models
cd models
gedit INSTANCIA_NOME_DO_SEU_PLUGIN.php
(Ex: pro_professional.php)
Adicione o seuinte codigo
<?php
class INSTANCIA_NOME_DO_SEU_PLUGIN extends NOME_DO_SEU_PLUGINAppModel {
var $name = 'INSTANCIA_NOME_DO_SEU_PLUGIN';
var $actsAs = array(
'Dashboard.DashDashboardable',
'Temp.TempTemp',
'JjMedia.StoredFileHolder' => array('img_id','cover_id'),
'Status.Status' => array('publishing_status'),
'ContentStream.CsContentStreamHolder' => array(
'streams' => array('content_id' => 'professional_content'),
)
);
function createEmpty() {
return $this->save(
array('INSTANCIA_NOME_DO_SEU_PLUGIN' =>
array('publishing_status' => 'draft')
),
array('validate' => false)
);
}
function getDashboardInfo($id) {
$data = $this->find('first', array(
'conditions' => array($this->alias.'.id' => $id),
'contain' => array()
));
if ($data == null)
return null;
$dashdata = array(
'dashable_id' => $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['id'],
'dashable_model'=> $this->name,
'type' => 'NOME_DO_SEU_SITE',
'status' => $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['publishing_status'],
'created' => $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['created'],
'modified' => $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['modified'],
'name' => $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['name'] . ' ' . $data['INSTANCIA_NOME_DO_SEU_PLUGIN']['last_name'],
'info' => 'Resumo: ' . substr($data['INSTANCIA_NOME_DO_SEU_PLUGIN']['abstract'], 0, 100),
'idiom' => null
);
return $dashdata;
}
}
4) Entre na views, elements Criar um elemento.ctp
cd views/elementes
gedit INSTANCIA_NOME_DO_SEU_PLUGIN.ctp
(Ex: pro_professional.ctp)
Adicione o Seguinte Codigo
<?php
switch ($type[0]) {
case 'buro':
switch ($type[1]) {
case 'form':
echo $this->Buro->sform(array(), array(
'model' => $fullModelName,
'callbacks' => array(
'onReject' => array(
'js' => '$("content").scrollTo(); showPopup("error");',
'contentUpdate' => 'replace'
),
'onSave' => array('js' => '$("content").scrollTo(); showPopup("notice")'),
)
)); {
echo $this->Buro->input(
null, array('type' => 'hidden', 'fieldName' => 'id')
);
echo $this->Buro->input(
null,
array(
'type' => 'text',
'fieldName' => 'name',
'label' => __d('professional', 'Nome', true),
)
);
echo $this->Buro->input(
null,
array(
'type' => 'text',
'fieldName' => 'last_name',
'label' => __d('professional', 'Sobrenome', true),
)
);
echo $this->Buro->input(
null,
array(
'type' => 'textarea',
'fieldName' => 'abstract',
'label' => __d('professional', 'Texto de Apresentação', true),
)
);
//profile img
{
$error = $this->Form->error('INSTANCIA_NOME_DO_SEU_PLUGIN.img_id');
if ($error)
echo $this->Bl->sdiv(
array('class' => 'input buro input_text required error')
);
echo $this->Buro->input(
null,
array(
'type' => 'image',
'fieldName' => 'img_id',
'label' => __d('professional', 'Foto', true),
'options' => array('version' => 'backstage_preview')
)
);
if ($error) {
echo $this->Form->error('INSTANCIA_NOME_DO_SEU_PLUGIN.img_id');
echo $this->Bl->ediv();
}
}
$contacts = $this->data['INSTANCIA_NOME_DO_SEU_PLUGIN']['contact'];
echo $this->Buro->sinput(
null,
array(
'type' => 'super_field',
'label' => 'Contato',
)
);
for ($i = 0; $i < count($contacts[0]); $i++) {
echo $this->Bl->sdiv(array('class' => 'fields'),array());
echo $this->Buro->input(
array(
'onchange' => 'AddFields(); return false',
'class' => 'title',
'value' => $contacts[0][$i],
),
array(
'type' => 'text',
'fieldName' => 'INSTANCIA_NOME_DO_SEU_PLUGIN.contact_title.' . $i,
'label' => __d('professional', 'Titulo', true),
)
);
echo $this->Buro->input(
array(
'onchange' => 'AddFields(); return false',
'class' => 'contact',
'value' => $contacts[1][$i],
),
array(
'type' => 'textarea',
'fieldName' => 'INSTANCIA_NOME_DO_SEU_PLUGIN.contact_value.' . $i,
'label' => __d('professional', 'Conteúdo', true),
)
);
echo $this->Bl->ediv();
}
echo $this->Bl->sdiv(array('class' => 'fields'),array());
echo $this->Buro->input(
array(
'onchange' => 'AddFields(); return false;',
'class' => 'title',
),
array(
'type' => 'text',
'fieldName' => 'INSTANCIA_NOME_DO_SEU_PLUGIN.contact_title.' . count($contacts[0]),
'label' => __d('professional', 'Titulo', true),
)
);
echo $this->Buro->input(
array(
'onchange' => 'AddFields(); return false;',
'class' => 'contact'
),
array(
'type' => 'textarea',
'fieldName' => 'INSTANCIA_NOME_DO_SEU_PLUGIN.contact_value.' . count($contacts[0]),
'label' => __d('professional', 'Conteúdo', true),
)
);
echo $this->Bl->ediv();
echo $this->Buro->einput();
echo $this->Html->scriptBlock('
function _(str) {
return document.getElementsByClassName(str);
}
var copy, newCopy, fields = _("fields");
window.onload = function() {
copy = fields[0].cloneNode(true);
copy.childNodes[1].childNodes[2].value = "";
copy.childNodes[3].childNodes[2].childNodes[2]. value = "";
}
function AddFields() {
var superfield = _("superfield_container")[0];
var title = _("title");
var contact = _("contact");
for (var i = 0; i < title.length; i++)
if (title[i].value == "" && contact[i].value == "") {
console.log(fields[i]);
superfield.removeChild(fields[i]);
}
if (title[--i].value != "" && contact[i].value != "") {
newCopy = copy.cloneNode(true);
i++;
newCopy.childNodes[1].childNodes[2].name = "data[INSTANCIA_NOME_DO_SEU_PLUGIN][contact_title]["+ i +"]";
newCopy.childNodes[1].childNodes[2].value = "";
newCopy.childNodes[3].childNodes[2].childNodes[2].name = "data[INSTANCIA_NOME_DO_SEU_PLUGIN][contact_value]["+ i +"]";
newCopy.childNodes[3].childNodes[2].childNodes[2].value = "";
superfield.appendChild(newCopy);
}
}
');
echo $this->Buro->submitBox(array(), array());
} echo $this->Buro->eform();
break;
}
break;
}
0 comentários: