Автоматическое выполнение несвязанного действия в приложении CakePhpPhp

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Автоматическое выполнение несвязанного действия в приложении CakePhp

Сообщение Anonymous »

Я работаю над небольшим приложением, чтобы предоставить цитаты для пользовательских продуктов. Это мое первое приложение CakePhp. < /P>
Многие из полей для продуктов рассчитываются автоматически при добавлении или сохранении продукта. Расчеты используют Valuse, хранящийся в таблице «ставки» для выполнения операций. Эти «ставки» также могут быть обновлены администратором и имеют свою собственную модель, просмотр и контроллер. Однако, когда ставки обновляются, мне нужны все существующие продукты, которые будут перечислены, как будто пользователь был в /products /edit и нажимал Save.public function edit($id = null) {
$this->Product->id = $id;
if (!$this->Product->exists()) {
throw new NotFoundException(__('Invalid product'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->loadModel('Rate', '1');

$Od = $this->request->data['Product']['material_od'] / 2;
$materialMass = $this->Rate->field('steel_mass') * $this->request->data['Product']['material_length'] * (pi() * $Od * $Od );
$this->Product->saveField('material_mass', $materialMass);

$materialCost = $materialMass * $this->Product->Material->field('cost', array('Material.id' => $this->request->data['Product']['material_id']));
$this->Product->saveField('material_cost', $materialCost);

$materialMarkupRate = $this->Rate->field('material_markup') + 1;
$wasteMarkupRate = $this->Rate->field('waste_markup') + 1;

$materialMarkupCost = $materialCost * $materialMarkupRate * $wasteMarkupRate;
$this->Product->saveField('material_markup_cost', $materialMarkupCost);

$setupCost = $this->request->data['Product']['number_tools'] * $this->Rate->field('tool_time') * $this->Rate->field('setup_rate');
$this->Product->saveField('setup_cost', $setupCost);

$cuttingCost = $this->request->data['Product']['cutting_time'] * $this->Rate->field('cutting_rate');
$this->Product->saveField('cutting_cost', $cuttingCost);

$machiningCost = $this->request->data['Product']['machining_time'] * $this->Rate->field('machining_rate');
$this->Product->saveField('machining_cost', $machiningCost);

$polishingCost = $this->request->data['Product']['polishing_time'] * $this->Rate->field('polishing_rate');
$this->Product->saveField('polishing_cost', $polishingCost);

if ($this->Product->save($this->request->data)) {
$this->Session->setFlash(__('The product has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The product could not be saved. Please, try again.'));
}
} else {
$this->request->data = $this->Product->read(null, $id);
}
$materials = $this->Product->Material->find('list');
$this->set(compact('materials'));
}
< /code>
и моя функция редактирования rafecontroller: < /p>
public function edit($id = null) {
$this->Rate->id = $id;
if (!$this->Rate->exists()) {
throw new NotFoundException(__('Invalid rate'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Rate->save($this->request->data)) {
$this->Session->setFlash(__('The settings have been saved. Please update your products.'));
$this->redirect(array('controller' => 'products', 'action' => 'index'));
} else {
$this->Session->setFlash(__('The rate could not be saved. Please, try again.'));
}
} else {
$this->request->data = $this->Rate->read(null, $id);
}
}
< /code>

Как я могу запустить первый со второго? < /p>

Подробнее здесь: https://stackoverflow.com/questions/927 ... pplication
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»