灯角

文章 0 评论 0 浏览 23

灯角 2024-10-15 01:43:04

根据原始问题中更新的代码进行更新

请记住,CodeIgniter 的 Hooks 类是在 Loader 类之前初始化的,因此您的 pre_controller 钩子正在实例化SiteObj 并尝试在通过 Loader 类加载 Site_model 之前调用 Site_model->create_site()

它会抛出错误,因为您无法在尚不存在的对象上调用方法。在本例中,Site_model 是尚不存在的对象。

请记住,您可以检查日志文件(位于 /system/logs/ 中)以查看资源的执行顺序。查看 CodeIgniter 应用程序流程图也可能会有所帮助。

希望有帮助!

结束更新

num_rows() 方法只能用于整个 $query 结果对象,就像您在您的 Site_model

$query = $this->db->query("SELECT * FROM sites WHERE siteid = '1' LIMIT 1");

if ($query->num_rows() > 0) {
        // do stuff
}

但是,目前 Site_model 中的 create_site() 方法返回单行return $row;) 从结果对象中调用,然后您尝试在 SiteObj 控制器中的该单行上调用 num_rows()

实际上没有必要这样做,因为 $query->row(); 将始终返回单个结果行。

如果您确实想从控制器内部调用 num_rows() (同样,这确实没有意义,因为 $query->row() 总是只返回一行),您必须像这样返回整个 $query 结果对象:

$query = $this->db->query("SELECT * FROM sites WHERE siteid = '1' LIMIT 1");

if ($query->num_rows() > 0) {
    return $query;
}

然后在您的 SiteObj 控制器中:

$this->load->model('Site_model');

$data = $this->Site_model->create_site();

if ($data->num_rows() == 1) {
    //etc. etc.
}

希望有帮助 - 如果没有请告诉我。看起来你的代码并不太遥远!作为参考,请查看 num_rows() 方法row() 方法

Update based on updated code in original question:

Keep in mind that CodeIgniter's Hooks Class is initialized before the Loader Class, so your pre_controller hook is instantiating SiteObj and trying to call Site_model->create_site() before Site_model has been loaded via the Loader Class.

It's throwing an error because you can't call a method on an object that doesn't exist yet. In this case Site_model is the object that doesn't exist yet.

Remember that you can check your log files (located in /system/logs/) to see the order in which resources are executed. It might also be helpful to review the CodeIgniter Application Flow Chart.

Hope that helps!

End Update

The num_rows() method can only be used on the entire $query result object like you have in your Site_model:

$query = $this->db->query("SELECT * FROM sites WHERE siteid = '1' LIMIT 1");

if ($query->num_rows() > 0) {
        // do stuff
}

However, currently your create_site() method in your Site_model is returning a single row (return $row;) from the result object, and then you're trying to call num_rows() on that single row in your SiteObj controller.

There really is no need to do this because $query->row(); will always return a single result row.

If you did absolutely want to call num_rows() from inside your controller (again, there's really no point since $query->row() will always return only one row), you must return the entire $query result object like this:

$query = $this->db->query("SELECT * FROM sites WHERE siteid = '1' LIMIT 1");

if ($query->num_rows() > 0) {
    return $query;
}

Then in your SiteObj controller:

$this->load->model('Site_model');

$data = $this->Site_model->create_site();

if ($data->num_rows() == 1) {
    //etc. etc.
}

Hope that helps - if not let me know. It doesn't look like your code is too far off! For reference, check out the num_rows() method and the row() method.

Codeigniter 控制器和模型的问题

灯角 2024-10-15 00:52:59

你的问题没有很好地定义,因为我们没有你的整个 XSLT 也没有所需的输出,但我会尝试一下:

如果你使用 for 循环来迭代不同的图像,你需要设置你的对循环本身的约束,而不是对循环内容的约束。

如果将示例代码放入 xsl:for-each 中,它将迭代每个图像,但仅在 image 时填充 @src 属性。其中 @size="medium" 是当前节点。这将为您提供三个表行,其中包含三个图像,但只有一个图像具有有效的 @src 属性。

相反,更改您的 xsl:for-each (或使用 xsl:apply-templates) 仅使用 @size="medium" 迭代图像:

<!-- This will only iterate over the medium sized images. -->
<xsl:for-each select="image[@size='medium']">
  <tr>
    <td>
      <img src="{.}"/>
    </td>
  </tr>
</xsl:for-each>

另一个提示:而不是使用 xsl:attribute 使用 属性值模板

Your question isn't very well defined since we don't have your whole XSLT nor the desired output, but I'll give it a try:

If you are using a for-loop to iterate over the different images you need to set your constraints on the loop itself, not the content of the loop.

If you put your example code inside a xsl:for-each it will iterate over every image but only fill the @src attribute when the image with @size="medium" is the current node. That would give you three table rows with three images but only one image with a valid @src attribute.

Instead change your xsl:for-each (or use xsl:apply-templates) to only iterate over your images with @size="medium":

<!-- This will only iterate over the medium sized images. -->
<xsl:for-each select="image[@size='medium']">
  <tr>
    <td>
      <img src="{.}"/>
    </td>
  </tr>
</xsl:for-each>

Another tip: instead of using xsl:attribute use an attribute value template.

获取 XSL、XML 中相同名称的 value-of

灯角 2024-10-15 00:36:23
/**
* Converts your record to XML.
* 
* @param array/object $record
* @return SimpleXMLElement
*/
function ConvertToXml($record){
    // Objects need to be arrays
    if(is_object($record)){
        $record = get_object_vars($record);
    }

    // We need an array argument
    if(!is_array($record)){
        trigger_error('$record must be an object or an array.', E_USER_WARNING);
        return null;
    }

    // Now we build XML
    ob_start();
    echo '<xml>', PHP_EOL;
    foreach($record as $name => $value){
        if(is_object($value) or is_array($value) or is_resource($value)){
            trigger_error('$record must have only scalar values.', E_USER_WARNING);
            return null;
        }
        if(!is_string($name) or !preg_match('~[a-z_][a-z0-9]*~i', $name)){
            trigger_error('$record must have only XML-tag friendly string keys.', E_USER_WARNING);
            return null;
        }

        // NULL produces an empty node
        if(is_null($value)){
            echo "<{$name} />", PHP_EOL;
            continue;
        }

        // Numerics don't need to be XML encoded
        if(is_integer($value) or is_float($value) or is_bool($value)){
            echo "<{$name}>{$value}</{$name}>", PHP_EOL;
            continue;
        }

        // We must have a string now
        if(!is_string($name)){
            trigger_error('$record must have only scalar values.', E_USER_WARNING);
            return null;
        }

        // Do we have an XML field?
        if(preg_match('~^\s*<.+>\s*$~s', $value)){
            // Test it for real!
            if($xml = @simplexml_load_string("<xml>{$value}</xml>")){
                echo $value, PHP_EOL;
                continue;
            }
        }

        // Now output random strings
        echo "<{$name}>", htmlentities($value, ENT_QUOTES, 'utf-8'), "</{$name}>", PHP_EOL;
    }
    echo '</xml>', PHP_EOL;

    // Store built XML
    $xml = ob_get_clean();

    // Load the built XML
    return @simplexml_load_string($xml);;
}

// Prepare an array
$record = array();
$record['ID'] = 1;
$record['Name'] = 'SomeName';
$record['Data'] = '<data><foo>one</foo><bar>two</bar></data>';
if($xml = ConvertToXml($record)){
    echo $xml->asXML();
}

^ 为后代提供答案。

/**
* Converts your record to XML.
* 
* @param array/object $record
* @return SimpleXMLElement
*/
function ConvertToXml($record){
    // Objects need to be arrays
    if(is_object($record)){
        $record = get_object_vars($record);
    }

    // We need an array argument
    if(!is_array($record)){
        trigger_error('$record must be an object or an array.', E_USER_WARNING);
        return null;
    }

    // Now we build XML
    ob_start();
    echo '<xml>', PHP_EOL;
    foreach($record as $name => $value){
        if(is_object($value) or is_array($value) or is_resource($value)){
            trigger_error('$record must have only scalar values.', E_USER_WARNING);
            return null;
        }
        if(!is_string($name) or !preg_match('~[a-z_][a-z0-9]*~i', $name)){
            trigger_error('$record must have only XML-tag friendly string keys.', E_USER_WARNING);
            return null;
        }

        // NULL produces an empty node
        if(is_null($value)){
            echo "<{$name} />", PHP_EOL;
            continue;
        }

        // Numerics don't need to be XML encoded
        if(is_integer($value) or is_float($value) or is_bool($value)){
            echo "<{$name}>{$value}</{$name}>", PHP_EOL;
            continue;
        }

        // We must have a string now
        if(!is_string($name)){
            trigger_error('$record must have only scalar values.', E_USER_WARNING);
            return null;
        }

        // Do we have an XML field?
        if(preg_match('~^\s*<.+>\s*$~s', $value)){
            // Test it for real!
            if($xml = @simplexml_load_string("<xml>{$value}</xml>")){
                echo $value, PHP_EOL;
                continue;
            }
        }

        // Now output random strings
        echo "<{$name}>", htmlentities($value, ENT_QUOTES, 'utf-8'), "</{$name}>", PHP_EOL;
    }
    echo '</xml>', PHP_EOL;

    // Store built XML
    $xml = ob_get_clean();

    // Load the built XML
    return @simplexml_load_string($xml);;
}

// Prepare an array
$record = array();
$record['ID'] = 1;
$record['Name'] = 'SomeName';
$record['Data'] = '<data><foo>one</foo><bar>two</bar></data>';
if($xml = ConvertToXml($record)){
    echo $xml->asXML();
}

^ An answer for posterity.

如何使用 SimpleXML 在 PHP 中合并两个 XML 文档?

灯角 2024-10-14 23:26:26

您需要查看 Web 保护库 的 AntiXSS 部分中的 GetSafeHTMLFragment 方法。这使用了一个白名单,其中的 HTML 被认为是“安全”的,用于 XSS 目的,任何不在白名单中的内容都会被删除。 Blowdart(在 WPL 团队工作)有一个很棒的关于使用该方法的博客文章

You'll want to have a look at the GetSafeHTMLFragment method in the AntiXSS section of the Web Protection Library. This uses a whitelist of what HTML is considered 'safe' for XSS purposes, anything not in the whitelist is stripped out. Blowdart (who works on the WPL team) has a great blogpost on using the method.

HttpUtility.HtmlEncode 安全吗?

灯角 2024-10-14 18:52:57

这样做:

var versionExisting = entities.Documents.Where(d => d.VersionNumber == versionID + ".pdf" || d.VersionNumber == versionID + ".null");

Do this:

var versionExisting = entities.Documents.Where(d => d.VersionNumber == versionID + ".pdf" || d.VersionNumber == versionID + ".null");

Linq to 实体中 OR 条件的 lambda 表达式

灯角 2024-10-14 18:52:07

您可以使用wordpress中已经包含的功能:

详细信息在这里:
http://codex.wordpress.org/Function_Reference/is_email

is_email()

<?php if ( is_email( '[email protected]' ) ) {
      echo 'email address is valid.';
} ?>

可能还想使用函数 username_exists()

http 验证“用户名” ://codex.wordpress.org/Function_Reference/username_exists

<?php  
       $username = $_POST['username'];
       if ( username_exists( $username ) )
           echo "Username In Use!";
       else
           echo "Username Not In Use!";
?>

You can use the already included function in wordpress:

Details here:
http://codex.wordpress.org/Function_Reference/is_email

is_email()

<?php if ( is_email( '[email protected]' ) ) {
      echo 'email address is valid.';
} ?>

Might also want to validate the 'username' using the function username_exists()

http://codex.wordpress.org/Function_Reference/username_exists

<?php  
       $username = $_POST['username'];
       if ( username_exists( $username ) )
           echo "Username In Use!";
       else
           echo "Username Not In Use!";
?>

安全吗?由用户将数据插入数据库..?

灯角 2024-10-14 18:09:18

测试以生成特定交易结果

在开发者测试环境以及生产环境中测试交易结果时,您可以通过使用旨在生成特定交易结果的测试信用卡号提交测试交易来生成特定的响应原因代码:Visa 测试信用卡号“ 4222222222222”。该卡号用于测试,并且只能用于该目的。通过将帐户置于测试模式或提交 x_test_request=TRUE 来提交测试交易,其中美元金额值等于您想要生成的响应原因代码。

例如,要测试 AVS 响应原因代码编号 27,请提交信用卡号“4222222222222”和金额“27.00”的测试交易。

要在实时环境中测试 AVS 或 CCV 响应,您需要提交具有正确街道地址、邮政编码和卡代码信息的实时交易以生成成功的响应,以及提交不正确的街道地址、邮政编码和卡代码信息以生成其他响应。您可以立即作废成功的交易,以防止处理实时测试交易。这可以在商户界面的未结算交易页面上快速完成。无法在开发人员测试环境中测试 AVS 或 CCV 响应。有关 AVS 的更多信息,请参阅商家集成指南,网址为 http://www.authorize.net/support/商人/

Testing to Generate Specific Transaction Results

When testing transaction results in the developer test environment as well as the production environment, you can produce a specific response reason code by submitting a test transaction using a test credit card number designed to generate specific transaction results: Visa test credit card number “4222222222222.” This card number is intended for testing and should only be used for that purpose. Submit the test transaction by either placing the account in Test Mode, or submitting x_test_request=TRUE, with a dollar amount value equal to the response reason code you would like to produce.

For example, to test the AVS response reason code number 27, submit the test transaction with the credit card number “4222222222222” and the amount “27.00.”

To test the AVS or CCV responses in the live environment, you will need to submit live transactions with correct street address, ZIP Code and Card Code information to generate successful responses, and incorrect street address, ZIP Code and Card Code information to generate other responses. You can void successful transactions immediately to prevent live test transactions from being processed. This can be done quickly on the Unsettled Transactions page of the Merchant Interface. It is not possible to test the AVS or CCV responses in the developer test environment. For more information about AVS, see the Merchant Integration Guide at http://www.authorize.net/support/merchant/.

Authorize.net 测试在测试模式下下降

灯角 2024-10-14 09:31:38

86400-(EventTimeStamp) 作为 new_users

86400-(EventTimeStamp) as new_users

MySQL 查询 - 查找“新”每日用户数

灯角 2024-10-14 07:00:12

ROWGUIDCOLUMN 主要用于需要将多个卫星数据库表的内容组合到一个中央数据库中的复制场景。

将 ROWGUIDCOLUMN 添加到正在复制的表中可确保复制引擎可以使用 ROWGUIDCOLUMN 字段来区分具有相同主键值的记录。

由于此功能主要用于确保顺利复制,因此您应避免使用此列作为主键。您的主键应该是一个逻辑业务实体,该实体在您的控制之下,并且不会影响您选择的数据库引擎的特定功能的操作特征。

The ROWGUIDCOLUMN is used primarily in replication scenarios where you need to combine the contents of several satelite databases' tables into one central DB.

Adding a ROWGUIDCOLUMN to the tables being replicated ensures that the replication engine can use the ROWGUIDCOLUMN field to differentiate between records with the same primary key values.

Because this is a feature primarily used to ensure smooth replication, you should avoid using this column as your primary key. Your primary key should be a logical business entity that is under your control and which doesn't affect the operational characteristics of specific features of your chosen DB engine.

MS SQL Server 行 GUID 列

灯角 2024-10-14 05:45:14

您可以使用以下查询代替 Account.where(:admin => false).count

Account.select(:id).where(:admin => false).count

只需选择一列,而不是选择全部。它生成以下查询,并且比前一个查询更快:

SELECT COUNT("accounts"."id") FROM "accounts" where admin = false

You can use following query instead of Account.where(:admin => false).count

Account.select(:id).where(:admin => false).count

Just select one column, instead of selecting all. It generates the following query and it is faster than the previous one:

SELECT COUNT("accounts"."id") FROM "accounts" where admin = false

在 Rails 中进行计数的正确方法是什么?

灯角 2024-10-14 04:23:12

自定义 Bean 工厂是一个具有创建 Bean 方法的类。有两种“风格”

a) 静态创建方法

SomeBean x = SomeBeanFactory.createSomeBean();

b) 实例创建方法

SomeBeanFactory sbf = new SomeBeanFactory();
SomeBean x = sbf.createSomeBean();

如果创建和设置 bean 需要一些棘手的逻辑(例如某些属性的初始值取决于外部配置文件),您将创建一个 bean 工厂。 bean 工厂类允许您集中有关如何创建如此棘手的 bean 的“知识”。其他类只是调用 create 方法,而不用担心如何正确创建这样的 bean。

A custom bean factory is a class that has a method that creates a bean. There are two "flavours"

a) static create method

SomeBean x = SomeBeanFactory.createSomeBean();

b) instance create method

SomeBeanFactory sbf = new SomeBeanFactory();
SomeBean x = sbf.createSomeBean();

You would create a bean factory if creating and setting up your bean requires some tricky logic, like for example initial value of certain properties depend on external configuration file. A bean factory class allows you to centralize "knowledge" about how to create such a tricky bean. Other classes just call create method without worying how to correctly create such bean.

Dozer BeanFactory:如何实现?

灯角 2024-10-13 18:29:28

您可以在 anddev.org 上找到一些线索。基本思想是扩展默认主题并在您的活动中使用它。特别是,您需要扩展 Theme.Dialog 样式。

You have some clues on anddev.org. The basic idea is to extend the default theme and use it in your activity. In particular, you will need to extend the Theme.Dialog style.

如何改变对话框的颜色

灯角 2024-10-13 18:03:18

正如 Dave Webb 的 freezeset 的替代方案一样,为什么不执行如下所示的 SymDict:

class SymDict(dict):
    def __getitem__(self, key):
        return dict.__getitem__(self, key if key[0] < key[1] else (key[1],key[0]))

    def __setitem__(self, key, value):
        dict.__setitem__(self, key if key[0] < key[1] else (key[1],key[0]), value)

从快速测试来看,这比使用 freezeset 获取和设置项目的速度快 10% 以上。无论如何,只是另一个想法。然而,它的适应性不如 freezeset,因为它实际上只设置为与长度为 2 的元组一起使用。据我从 OP 中可以看出,这似乎不是问题。

Just as an alternative to Dave Webb's frozenset, why not do a SymDict like the following:

class SymDict(dict):
    def __getitem__(self, key):
        return dict.__getitem__(self, key if key[0] < key[1] else (key[1],key[0]))

    def __setitem__(self, key, value):
        dict.__setitem__(self, key if key[0] < key[1] else (key[1],key[0]), value)

From a quick test, this is more than 10% faster for getting and setting items than using a frozenset. Anyway, just another idea. However, it is less adaptable than the frozenset as it is really only set up to be used with tuples of length 2. As far as I can tell from the OP, that doesn't seem to be an issue here.

对称字典,其中 d[a][b] == d[b][a]

灯角 2024-10-13 11:51:23

把丑陋写一次,然后隐藏起来

def check_all_present(hash, keys)
  current_hash = hash
  keys.each do |key|
    return false unless current_hash[key]
    current_hash = current_hash[key]
  end
  true
end

Write the ugliness once, then hide it

def check_all_present(hash, keys)
  current_hash = hash
  keys.each do |key|
    return false unless current_hash[key]
    current_hash = current_hash[key]
  end
  true
end

如何避免嵌套哈希中缺少元素的 NoMethodError,而不需要重复的 nil 检查?

灯角 2024-10-13 11:39:56

在这种情况下,端口模式负责。您在等待模式(默认情况下处于打开状态)中使用缓冲 I/O。

在http中,当您读取所有服务器字节后,客户端负责关闭端口。

由于您基本上直接使用 TCP,使用插入端口,因此您还负责检测请求的结束并在足够的字节到达时关闭端口。这只能在进行低级 tcp 乐趣时在 /lines 或 /no-wait 中完成。

阅读和信息的东西?为你做。

而 [data: copy port][append out data]

直到发生超时(REBOL 中默认为 30 秒)才会终止。

另外,您的请求似乎有错误...

试试这个:

port: open/lines tcp://cdimage.ubuntu.com:80
insert port {HEAD /daily/current/natty-alternate-i386.iso HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.7.3.1
Host: cdimage.ubuntu.com
}
out: form copy port
block: parse out none ;rejoin [": ^/"]
probe select block "Content-Length:"

在这里添加 /lines 似乎会阻止等待。它可能与http方案如何处理打开时的线路模式有关。

在文档中查找 REBOL 端口模式,并在网上对其进行了很好的解释。

如果您使用了trace/net,您就会意识到所有数据包都已收到,并且解释器仍在等待。顺便说一句,您的代码实际上在我的测试中返回了错误 400。

the port modes are responsible in this case. you where using buffered I/O with the wait mode (which is on by default).

in http, the client is responsible closing of the port when you've read all the server bytes.

since you are basically using tcp directly, using insert port, you are responsible for also detecting the end of the request and closing the port when sufficient bytes have arrived. this can only be done in /lines or /no-wait when doing low-level tcp fun.

Something that read and info? do for you.

while [data: copy port][append out data]

doesn't terminate until a timeout occurs (which is 30 seconds by default in REBOL).

also, your request seems to be in error...

try this:

port: open/lines tcp://cdimage.ubuntu.com:80
insert port {HEAD /daily/current/natty-alternate-i386.iso HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.7.3.1
Host: cdimage.ubuntu.com
}
out: form copy port
block: parse out none ;rejoin [": ^/"]
probe select block "Content-Length:"

here it seems that adding /lines will prevent the wait. its probably related to how the http scheme handles the line mode on open.

look around for REBOL port modes within the documentation and on the net its well explained all over the place.

if you had used trace/net on, you'd realized that all the packets where received and that the interpreter was just still waiting. btw your code actually returned an error 400 in my tests.

为什么 Rebol Raw Http Head Request 获取远程文件大小与信息相比非常慢?功能

更多

推荐作者

吝吻

文章 0 评论 0

Jasmine

文章 0 评论 0

∞梦里开花

文章 0 评论 0

阳光①夏

文章 0 评论 0

暮念

文章 0 评论 0

梦里泪两行

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文