<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Forum CakePHP.org.pl - Nie mogę edytować rekordów]]></title>
		<link>http://forum.cakephp.org.pl/topic/102/nie-moge-edytowac-rekordow/</link>
		<description><![CDATA[Najświeższe odpowiedzi w Nie mogę edytować rekordów.]]></description>
		<lastBuildDate>Tue, 25 Aug 2009 13:24:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Odp: Nie mogę edytować rekordów]]></title>
			<link>http://forum.cakephp.org.pl/post/493/#p493</link>
			<description><![CDATA[<p>Zeby aktualizowac musisz wysłac id produktu do aktualizacji jako hidden</p>]]></description>
			<author><![CDATA[null@example.com (duke_piotr)]]></author>
			<pubDate>Tue, 25 Aug 2009 13:24:55 +0000</pubDate>
			<guid>http://forum.cakephp.org.pl/post/493/#p493</guid>
		</item>
		<item>
			<title><![CDATA[Nie mogę edytować rekordów]]></title>
			<link>http://forum.cakephp.org.pl/post/492/#p492</link>
			<description><![CDATA[<p>witam,<br />mam dziwny problem ponieważ nie mogę edytować rekordu. Zamiast edycji, wstawia nowy, oparty na starym.</p><p>tak wyglada moj model<br /></p><div class="codebox"><pre><code>&lt;?php
class Product extends AppModel {

    var $name = &#039;Product&#039;;
    var $validate = array(
        &#039;name&#039; =&gt; array(&#039;notempty&#039;),
        
        &#039;status&#039; =&gt; array(&#039;numeric&#039;),
        
    );
    
    var $order = array(&#039;Product.name ASC&#039;);
    
    var $actsAs = array(&#039;Sluggable&#039;=&gt;array(&#039;label&#039;=&gt;&#039;name&#039;,&#039;separator&#039;=&gt;&#039;-&#039;,&#039;translation&#039;=&gt;&#039;utf-8&#039;),&#039;Translate&#039;=&gt;array(&#039;name&#039;,&#039;description&#039;));
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $hasMany = array(
        &#039;Ad&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Ad&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;dependent&#039; =&gt; false,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;exclusive&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;counterQuery&#039; =&gt; &#039;&#039;
        ),
        &#039;Fact&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Fact&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;dependent&#039; =&gt; false,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;exclusive&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;counterQuery&#039; =&gt; &#039;&#039;
        ),
        &#039;Question&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Question&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;dependent&#039; =&gt; false,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;exclusive&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;counterQuery&#039; =&gt; &#039;&#039;
        ),
        &#039;Science&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Science&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;dependent&#039; =&gt; false,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;exclusive&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;counterQuery&#039; =&gt; &#039;&#039;
        ),
        &#039;Testimonial&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Testimonial&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;dependent&#039; =&gt; false,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;exclusive&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;counterQuery&#039; =&gt; &#039;&#039;
        )
    );

    var $hasAndBelongsToMany = array(
        &#039;Category&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Category&#039;,
            &#039;joinTable&#039; =&gt; &#039;categories_products&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;associationForeignKey&#039; =&gt; &#039;category_id&#039;,
            &#039;unique&#039; =&gt; true,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;deleteQuery&#039; =&gt; &#039;&#039;,
            &#039;insertQuery&#039; =&gt; &#039;&#039;
        ),
        &#039;Clip&#039; =&gt; array(
            &#039;className&#039; =&gt; &#039;Clip&#039;,
            &#039;joinTable&#039; =&gt; &#039;clips_products&#039;,
            &#039;foreignKey&#039; =&gt; &#039;product_id&#039;,
            &#039;associationForeignKey&#039; =&gt; &#039;clip_id&#039;,
            &#039;unique&#039; =&gt; true,
            &#039;conditions&#039; =&gt; &#039;&#039;,
            &#039;fields&#039; =&gt; &#039;&#039;,
            &#039;order&#039; =&gt; &#039;&#039;,
            &#039;limit&#039; =&gt; &#039;&#039;,
            &#039;offset&#039; =&gt; &#039;&#039;,
            &#039;finderQuery&#039; =&gt; &#039;&#039;,
            &#039;deleteQuery&#039; =&gt; &#039;&#039;,
            &#039;insertQuery&#039; =&gt; &#039;&#039;
        )
    );

}
?&gt;</code></pre></div><p>kontroler:<br /></p><div class="codebox"><pre><code>&lt;?php
class ProductsController extends AppController {

    var $name = &#039;Products&#039;;
    var $helpers = array(&#039;Html&#039;, &#039;Form&#039;);
    
    function index() {
        $this-&gt;Product-&gt;recursive = 0;
        $this-&gt;set(&#039;products&#039;, $this-&gt;paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this-&gt;Session-&gt;setFlash(__(&#039;Invalid Product.&#039;, true));
            $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
        }
        $this-&gt;set(&#039;product&#039;, $this-&gt;Product-&gt;read(null, $id));
    }    

    function admin_index() {
        $this-&gt;Product-&gt;recursive = 0;
        $this-&gt;set(&#039;products&#039;, $this-&gt;paginate());
    }

    function admin_view($id = null) {
        if (!$id) {
            $this-&gt;Session-&gt;setFlash(__(&#039;Invalid Product.&#039;, true));
            $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
        }
        $this-&gt;set(&#039;product&#039;, $this-&gt;Product-&gt;read(null, $id));
    }

    function admin_add() {
        if (!empty($this-&gt;data)) {
            $this-&gt;Product-&gt;create();
            if ($this-&gt;Product-&gt;save($this-&gt;data)) {
                $this-&gt;Session-&gt;setFlash(__(&#039;The Product has been saved&#039;, true));
                $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
            } else {
                $this-&gt;Session-&gt;setFlash(__(&#039;The Product could not be saved. Please, try again.&#039;, true));
            }
        }
        $clips = $this-&gt;Product-&gt;Clip-&gt;find(&#039;list&#039;);
        $this-&gt;set(compact(&#039;clips&#039;));
    }

    function admin_edit($id = null) {
        if (!$id &amp;&amp; empty($this-&gt;data)) {
            $this-&gt;Session-&gt;setFlash(__(&#039;Invalid Product&#039;, true));
            $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
        }
        if (!empty($this-&gt;data)) {
            if ($this-&gt;Product-&gt;saveAll($this-&gt;data)) {
                $this-&gt;Session-&gt;setFlash(__(&#039;The Product has been saved&#039;, true));
                $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
            } else {
                $this-&gt;Session-&gt;setFlash(__(&#039;The Product could not be saved. Please, try again.&#039;, true));
            }
        }
        if (empty($this-&gt;data)) {
            $this-&gt;data = $this-&gt;Product-&gt;read(null, $id);
        }
        $clips = $this-&gt;Product-&gt;Clip-&gt;find(&#039;list&#039;);
        $this-&gt;set(compact(&#039;clips&#039;));
    }

    function admin_delete($id = null) {
        if (!$id) {
            $this-&gt;Session-&gt;setFlash(__(&#039;Invalid id for Product&#039;, true));
            $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
        }
        if ($this-&gt;Product-&gt;del($id)) {
            $this-&gt;Session-&gt;setFlash(__(&#039;Product deleted&#039;, true));
            $this-&gt;redirect(array(&#039;action&#039;=&gt;&#039;index&#039;));
        }
    }

}
?&gt;</code></pre></div><p>no i widok<br /></p><div class="codebox"><pre><code>&lt;div class=&quot;products form&quot;&gt;
&lt;?php echo $form-&gt;create(&#039;Product&#039;);?&gt;
    &lt;fieldset&gt;
         &lt;legend&gt;&lt;?php __(&#039;Edit Product&#039;);?&gt;&lt;/legend&gt;
    &lt;?php
        echo $form-&gt;input(&#039;name&#039;);
        echo $form-&gt;input(&#039;description&#039;);
        echo $form-&gt;input(&#039;images&#039;);
        echo $form-&gt;input(&#039;flash&#039;);
        echo $form-&gt;input(&#039;status&#039;);
        echo $form-&gt;input(&#039;slug&#039;);
        echo $form-&gt;input(&#039;date&#039;);
        echo $form-&gt;input(&#039;Clip&#039;);
        echo $form-&gt;input(&#039;Category&#039;);
    ?&gt;
    &lt;/fieldset&gt;
&lt;?php echo $form-&gt;end(&#039;Submit&#039;);?&gt;
&lt;/div&gt;
&lt;div class=&quot;actions&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;?php echo $html-&gt;link(__(&#039;Delete&#039;, true), array(&#039;action&#039; =&gt; &#039;delete&#039;, $form-&gt;value(&#039;Product.id&#039;)), null, sprintf(__(&#039;Are you sure you want to delete # %s?&#039;, true), $form-&gt;value(&#039;Product.id&#039;))); ?&gt;&lt;/li&gt;
        &lt;li&gt;&lt;?php echo $html-&gt;link(__(&#039;List Products&#039;, true), array(&#039;action&#039; =&gt; &#039;index&#039;));?&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;</code></pre></div><p>czyli kod wyglada zupełnie standardowo, jednak w rekord nie jest aktualizowany tylko dodawany nowy. Czy ktoś ma jakis pomysł?</p><p>pozdr.</p>]]></description>
			<author><![CDATA[null@example.com (gaw)]]></author>
			<pubDate>Tue, 25 Aug 2009 12:20:21 +0000</pubDate>
			<guid>http://forum.cakephp.org.pl/post/492/#p492</guid>
		</item>
	</channel>
</rss>

