Have you ever tried to change an object’s primary key in Propel? Well…it’s not as simple like call setters and save(). The problem is that you’re changing the primary key in the object and then you’re asking the object to build the UPDATE SQL. I’m not sure what the correct approach is to this issue, but Propel is clearly not paritularly adept at updating primary keys.
So, the solution is to use the BasePeer::doUpdate() method.
$con = Propel::getConnection(ProductPeer::DATABASE_NAME);
$product = ProductPeer::retrieveByPK(10, 'en');
$selectCriteria = $product->buildPkeyCriteria();
// update values are also stored in Criteria object
$product->setId(12);
$product->setLang('en');
$product->setParam('a');
$updateValues = $product->buildCriteria();
BasePeer::doUpdate($selectCriteria, $updateValues, $con);
No, it’s not.
But maybe you won’t find the solution for hours if I explain the details… :)
During a recent project, I started to deal with the Prado framework. Prado borrowed many ideas from Microsoft ASP.NET. This framework has in mind since June 2004, but from version 3.0, significant efforts are allocated to ensure the quality and stability of Prado. After trying most of available frameworks (Symfony, CakePHP, Zend), I felt that something else would be needed, something like ASP.NET. The key strength is its large number of components.
As for me, Prado is the most comfortable PHP framework that I’ve ever tried. This is not because it’s long been developing in ASP.NET and now I started to get to know someone else. On the contrary, I develop in PHP for 7 years, but a few years ago I began to fond of component based frameworks, and where web development is concerned, the event driven programming is more logical to me than strict MVC. It takes time to understand, but once you understand it, this will help in rapid development. The only annoying thing is that there is no IDE support for Prado templating (except something for Dreamweaver MX, but I’d rather relegate it). Well, you can expect a few blog posts about Prado tricks… :)
Contrary to popular belief, Prado is still under development. PRADO 4 is going to be a major rewrite of almost the whole framework (mostly backwards compatible to PRADO 3). The whole PRADO 4 core has been rewritten from scratch. Details:
„As the title implies, the exporter script runs in Blender. Simply construct a 2D scene using planes, add in an animation track, run the script and click Export. It’s as simple as that!”
wonderful idea.
Our recent ASP.NET project has began to grow bigger and bigger, so yesterday I decided to grab all business logic from the project, separate to components and put them into class libraries. Mostly I used some automated copying process, but in ‘ClientManagerClassLibrary’ I had to recreate my ‘ClientProfile’ LINQ to SQL class using the built-in wizard in Visual Studio 2008 SP1 (…sure you know the process: Add new item -> LINQ to SQL class -> dropping the table and stored procedures into designer -> Save). After separating, the project still worked fine on my developer machine, not like on my server. I got this error:
SQL Server 2005 Error: “A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) ”
I could not imagine what the hell is wrong with SQL Server. My connection string and SQL configuration the same on both machine and I didn’t modify that. So what else?
The solution have found in LINQ codebehinds.
<asp:ListView ID="livComments" runat="server" DataSourceID="CommentsObjectDataSource" EnableViewState="False" onitemcommand="livComments_ItemCommand" >
<ItemTemplate>
... /template here/ ...
</ItemTemplate>
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
<asp:DataPager ID="CommentDataPager" runat="server" PageSize="5">
<Fields>
<asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
<PagerTemplate>
<asp:Button ID="FirstButton" runat="server" CssClass="first" CommandName="First" Text="First" Enabled='<%# Container.StartRowIndex > 0 %>' />
<asp:Button ID="PreviousButton" runat="server" CommandName="Previous" Text='<%# (Container.StartRowIndex - Container.PageSize + 1).ToString() + " - " + (Container.StartRowIndex).ToString() %>' Visible='<%# Container.StartRowIndex > 0 %>' />
<!--<asp:Label ID="CurrentPageLabel" runat="server" Text='<%# (Container.StartRowIndex + 1).ToString() + "-" + ((Container.StartRowIndex + Container.PageSize > Container.TotalRowCount) ? (Container.TotalRowCount) : (Container.StartRowIndex + Container.PageSize)).ToString() %>' />-->
<asp:Button ID="NextButton" runat="server" CommandName="Next" Text='<%# (Container.StartRowIndex + Container.PageSize + 1).ToString() + " - " + ((Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount) ? (Container.TotalRowCount) : (Container.StartRowIndex + Container.PageSize*2)).ToString() %>' Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
<asp:Button ID="LastButton" runat="server" CssClass="last" CommandName="Last" Text='Last' Enabled='<%# Container.StartRowIndex < (Container.TotalRowCount - Container.PageSize) %>'/>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
</LayoutTemplate>
</asp:ListView>
You’ll get something like this:
