<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum CakePHP.org.pl - Problem z przechwytywaniem danych]]></title>
	<link rel="self" href="http://forum.cakephp.org.pl/feed/atom/topic/24/"/>
	<updated>2008-11-24T21:21:28Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.cakephp.org.pl/topic/24/problem-z-przechwytywaniem-danych/</id>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/70/#p70"/>
			<content type="html"><![CDATA[<p>Dobrym rozwiązaniem na problemy z cache&#039;owaniem w trakcie pisania aplikacji jest ustawienie zmiennej debug na 2 lub 3 w pliku app/config/core.php</p><p>Wtedy nie trzeba manualnie usuwać cache po każdej zmianie w widokach i dodatkowo wyświetla się fajne podsumowanie sql&#039;owych kwerend <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[darek_dobron]]></name>
				<uri>http://forum.cakephp.org.pl/user/39/</uri>
			</author>
			<updated>2008-11-24T21:21:28Z</updated>
			<id>http://forum.cakephp.org.pl/post/70/#p70</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/69/#p69"/>
			<content type="html"><![CDATA[<p>udało się, działa <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Problem został usunięty w momencie usunięcia cache-a modelu POst <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[Fallen]]></name>
				<uri>http://forum.cakephp.org.pl/user/71/</uri>
			</author>
			<updated>2008-11-24T11:57:19Z</updated>
			<id>http://forum.cakephp.org.pl/post/69/#p69</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/68/#p68"/>
			<content type="html"><![CDATA[<p>Dzięki <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />Ale niestety napotkałem kolejny problem <img src="http://forum.cakephp.org.pl/img/smilies/hmm.png" width="15" height="15" alt="hmm" /></p><p>Mam coś takiego:<br /></p><div class="codebox"><pre><code>&lt;div class=&quot;posts form&quot;&gt;
&lt;form id=&quot;PostAddForm&quot; method=&quot;post&quot; action=&quot;/cake/posts/add&quot;&gt;
&lt;fieldset style=&quot;display:none;&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;_method&quot; value=&quot;POST&quot; /&gt;&lt;/fieldset&gt;&lt;fieldset&gt;
&lt;legend&gt;New Post&lt;/legend&gt;
&lt;input type=&quot;hidden&quot; name=&quot;data[Post][id]&quot; value=&quot;&quot; id=&quot;PostId&quot; /&gt;
&lt;label for=&quot;PostTitle&quot;&gt;Title&lt;/label&gt;&lt;input name=&quot;data[Post][title]&quot; type=&quot;text&quot; length=&quot;120&quot; value=&quot;&quot; id=&quot;PostTitle&quot; /&gt;&lt;br&gt;
&lt;label for=&quot;PostBody&quot;&gt;Body&lt;/label&gt;&lt;textarea name=&quot;data[Post][body]&quot; cols=&quot;30&quot; rows=&quot;6&quot; id=&quot;PostBody&quot; &gt;&lt;/textarea&gt;&lt;br&gt;
&lt;label for=&quot;PostAutor&quot;&gt;Autor&lt;/label&gt;&lt;input name=&quot;data[Post][autor]&quot; type=&quot;text&quot; length=&quot;120&quot; value=&quot;&quot; id=&quot;PostAutor&quot; /&gt;
&lt;/fieldset&gt;
&lt;div class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/div&gt;&lt;/form&gt;&lt;/div&gt;</code></pre></div><p>Wszystko sie ładnie dodaje prócz&nbsp; data[Post][autor], why?<br />Dodałem dodatkowe pole w tabeli <img src="http://forum.cakephp.org.pl/img/smilies/hmm.png" width="15" height="15" alt="hmm" /><br />Podobna sytuacja jest w druga stronę kiedy nawet dodam ręcznie autora, cake nie chce szczytywać go z bazy:/<br /></p><div class="codebox"><pre><code>&lt;?php foreach ($data as $post): ?&gt;
echo $post[&#039;Post&#039;][&#039;title&#039;]; - działa
echo $post[&#039;Post&#039;][&#039;body&#039;]; - działa
echo $post[&#039;Post&#039;][&#039;created&#039;]; - działa
echo $post[&#039;Post&#039;][&#039;autor&#039;]; - nie działa</code></pre></div><p>Czy wina może sie brać z faktu że pole autor dołączyłem po pewnym czasie a wcześniej all działało bez tego pola?</p>]]></content>
			<author>
				<name><![CDATA[Fallen]]></name>
				<uri>http://forum.cakephp.org.pl/user/71/</uri>
			</author>
			<updated>2008-11-24T10:18:19Z</updated>
			<id>http://forum.cakephp.org.pl/post/68/#p68</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/67/#p67"/>
			<content type="html"><![CDATA[<div class="quotebox"><cite>Fallen napisał/a:</cite><blockquote><p>dzięki działa <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Teraz staram sie zrobić logowanie <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p></blockquote></div><p>Jeśli chcesz coś prostego to polecam <a href="http://bakery.cakephp.org/articles/view/simple-form-authentication-in-1-2-x-x">http://bakery.cakephp.org/articles/view … in-1-2-x-x</a></p>]]></content>
			<author>
				<name><![CDATA[darek_dobron]]></name>
				<uri>http://forum.cakephp.org.pl/user/39/</uri>
			</author>
			<updated>2008-11-24T07:41:55Z</updated>
			<id>http://forum.cakephp.org.pl/post/67/#p67</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/66/#p66"/>
			<content type="html"><![CDATA[<p>dzięki działa <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Teraz staram sie zrobić logowanie <img src="http://forum.cakephp.org.pl/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[Fallen]]></name>
				<uri>http://forum.cakephp.org.pl/user/71/</uri>
			</author>
			<updated>2008-11-23T21:52:54Z</updated>
			<id>http://forum.cakephp.org.pl/post/66/#p66</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Odp: Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/65/#p65"/>
			<content type="html"><![CDATA[<p>Rozwiązaniem może być wstawienie id posta przed save&#039;m, tak aby funkcja miała postać:</p><div class="codebox"><pre><code>function add($post_id) {

$this-&gt;set(&#039;post_id&#039;,$post_id);

if (!empty($this-&gt;data)) {
          $this-&gt;data[&#039;Comment&#039;][&#039;post_id&#039;]=$post_id;
            if ($this-&gt;Comment-&gt;save($this-&gt;data)) {
                $this-&gt;flash(&#039;Your Comment has been saved.&#039;, &#039;/posts&#039;);
            }
        }
 }</code></pre></div><p>Wtedy konieczne jeszcze jest dodanie numeru posta w akcji formularza (wcześniej trzeba tą wartość przekazać w kontrolerze):<br />Pola CommentId i PostId będą w tym wypadku w formularzxu zbędne, ponieważ PostId wypełniane jest przed dodaniem komentarza natomiast CommentId powstaje dopiero po wstawieniu komentarza do bazy. Formularz miałby więc postać zbliżoną do:</p><div class="codebox"><pre><code>&lt;div class=&quot;comment form&quot;&gt;
&lt;form id=&quot;CommentAddForm&quot; method=&quot;post&quot; action=&quot;/cake/app/webroot/index.php/comments/add/&lt;?php echo $post_id; ?&gt;&quot;&gt;
&lt;fieldset style=&quot;display:none;&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;_method&quot; value=&quot;POST&quot; /&gt;&lt;/fieldset&gt;&lt;fieldset&gt;&lt;legend&gt;New Comment&lt;/legend&gt;
&lt;div class=&quot;input text&quot;&gt;&lt;label for=&quot;CommentAuthor&quot;&gt;Author&lt;/label&gt;
&lt;input name=&quot;data[Comment][author]&quot; type=&quot;text&quot; maxlength=&quot;50&quot; value=&quot;&quot; id=&quot;CommentAuthor&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;input textarea&quot;&gt;&lt;label for=&quot;CommentBody&quot;&gt;Body&lt;/label&gt;&lt;textarea name=&quot;data[Comment][body]&quot; cols=&quot;30&quot; rows=&quot;6&quot; id=&quot;CommentBody&quot; &gt;&lt;/textarea&gt;
&lt;/div&gt;&lt;/fieldset&gt;&lt;div class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/div&gt;&lt;/form&gt;&lt;/div&gt;</code></pre></div><p>Niestety przy dodawaniu posta użytkownik będzie mógł wpisać w adres przeglądarki dowolny numer po comments/add/ i potrzebna będzie dobra walidacja. Drugie możliwe rozwiązanie to użycie sesji do przekazania wartości zmiennej post_id.</p>]]></content>
			<author>
				<name><![CDATA[darek_dobron]]></name>
				<uri>http://forum.cakephp.org.pl/user/39/</uri>
			</author>
			<updated>2008-11-23T20:30:22Z</updated>
			<id>http://forum.cakephp.org.pl/post/65/#p65</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problem z przechwytywaniem danych]]></title>
			<link rel="alternate" href="http://forum.cakephp.org.pl/post/64/#p64"/>
			<content type="html"><![CDATA[<p>Mam problem z przechwytywaniem danych <img src="http://forum.cakephp.org.pl/img/smilies/sad.png" width="15" height="15" alt="sad" /></p><p>Sytuacja wygląda następująco mam link który prowadzi do formularze z dodawaniem komentarza:</p><div class="codebox"><pre><code>&lt;?php echo $html-&gt;link(&#039;Dodaj Komentarz&#039;,
 &#039;/comments/add/&#039;.$data[&#039;Post&#039;][&#039;id&#039;]); ?&gt;</code></pre></div><p>Oraz funkcje która służy do dodawania do bazy komentarza:</p><div class="codebox"><pre><code>function add($post_id) {

if (!empty($this-&gt;data)) {
            if ($this-&gt;Comment-&gt;save($this-&gt;data)) {
                $this-&gt;flash(&#039;Your Comment has been saved.&#039;, &#039;/posts&#039;);
            }
        }
 }</code></pre></div><p>Czy aby funkcja add przechwyciła $data[&#039;Post&#039;][&#039;id&#039;],<br />wystarczy&nbsp; $this-&gt;Post-&gt;setPost_id($post_id), a jeżeli tak to w którym miejscu trzeba ją wstawić ?(kiedy wstawiam ją na początku funkcji nie działam, tak samo w warunku)</p><p>Czy trzeba to rozwiązać inaczej?<br />Tak aby pole Post_id w zapisywanym komentarzu miało wartość&nbsp; &nbsp;$data[&#039;Post&#039;][&#039;id&#039;] ??</p><p>Kod formularza dodającego komentarz:</p><div class="codebox"><pre><code>&lt;div class=&quot;comment form&quot;&gt;
&lt;form id=&quot;CommentAddForm&quot; method=&quot;post&quot; action=&quot;/cake/app/webroot/index.php/comments/add&quot;&gt;
&lt;fieldset style=&quot;display:none;&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;_method&quot; value=&quot;POST&quot; /&gt;&lt;/fieldset&gt;&lt;fieldset&gt;&lt;legend&gt;New Comment&lt;/legend&gt;
&lt;input type=&quot;hidden&quot; name=&quot;data[Comment][id]&quot; value=&quot;&quot; id=&quot;CommentId&quot; /&gt;&lt;div class=&quot;input select&quot;&gt;&lt;label for=&quot;CommentPostId&quot;&gt;Post&lt;/label&gt;&lt;input type=&quot;hidden&quot; name=&quot;data[Comment][post_id]&quot; value=&quot;&quot; id=&quot;CommentPostId&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;input text&quot;&gt;&lt;label for=&quot;CommentAuthor&quot;&gt;Author&lt;/label&gt;
&lt;input name=&quot;data[Comment][author]&quot; type=&quot;text&quot; maxlength=&quot;50&quot; value=&quot;&quot; id=&quot;CommentAuthor&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;input textarea&quot;&gt;&lt;label for=&quot;CommentBody&quot;&gt;Body&lt;/label&gt;&lt;textarea name=&quot;data[Comment][body]&quot; cols=&quot;30&quot; rows=&quot;6&quot; id=&quot;CommentBody&quot; &gt;&lt;/textarea&gt;
&lt;/div&gt;&lt;/fieldset&gt;&lt;div class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/div&gt;&lt;/form&gt;&lt;/div&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Fallen]]></name>
				<uri>http://forum.cakephp.org.pl/user/71/</uri>
			</author>
			<updated>2008-11-23T11:02:37Z</updated>
			<id>http://forum.cakephp.org.pl/post/64/#p64</id>
		</entry>
</feed>

